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
    '''
    

  • 相关阅读:
    TortoiseGit
    申请成功
    web.xml文件中配置ShallowEtagHeaderFilter需注意的问题
    消息队列调研
    二阶段提交
    ACID CAP BASE介绍
    SQL NULL Values
    HTTPS原理
    ID生成器详解
    如何变得更聪明
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501239.html
Copyright © 2011-2022 走看看