zoukankan      html  css  js  c++  java
  • 用python 重命名文件夹下文件

    # -*- coding: utf-8 -*-
    import os
    '''
    Description:
        when we load xls data into unix ,the file name with some space while our process can not recognise those file,
        so we want to write a samll a process and put it on unix to rename the files
    '''
    def renamefile():
        path = 'C:\Users\IBM_ADMIN\Desktop\cognos\datastage\excel\1Q-4Q files'
        filelist = os.listdir(path)
        for file in filelist:
            Oldfile =  os.path.join(path,file)
            if os.path.isdir(Oldfile):
                continue
            filename=os.path.splitext(file)[0]
            filetype=os.path.splitext(file)[1]
            newfilename = filename.replace(' ','_')
            Newfile=os.path.join(path,newfilename+filetype)
            os.rename(Oldfile,Newfile)
    print "Process is going...."
    renamefile();
    
    print "Process done"
    
    '''
    ls -lt target*| head -10
    '''
    

  • 相关阅读:
    个人作业——软件工程实践总结作业
    BETA答辩总结
    beta冲刺7
    beta冲刺6
    beta冲刺5
    beta冲刺4
    beta冲刺3
    华为云
    beta冲刺2
    beta冲刺1
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501239.html
Copyright © 2011-2022 走看看