zoukankan      html  css  js  c++  java
  • python更改文件夹下文件名字

    '''
    Created on 2013-1-2
    
    @author: buptlishantao
    '''
    
    #!/usr/bin/python
    
    import re
    import os
    import time
    
    def change_name(path):
        global i
        if not os.path.isdir(path) and not os.path.isfile(path):
        
            return False
        if os.path.isfile(path):
        
            file_path = os.path.split(path) #split the path  into path name   and file name
            
            lists = file_path[1].split('.')
            file_ext = lists[-1] 
            img_ext = ['bmp','jpeg','gif','psd','png','JPG','jpg']
            if file_ext in img_ext:
            
                os.rename(path,file_path[0]+'/'+lists[0]+'_fc.'+file_ext)
                i+=1 
            
        elif os.path.isdir(path):
            for x in os.listdir(path):
            
                change_name(os.path.join(path,x)) 
    img_dir = os.getcwd()
    start = time.time()
    i = 0
    print img_dir
    change_name(img_dir)
    c = time.time()-start
    print('time:%0.2f'%(c))
    print('number %s '%(i))
    
     
    
     
  • 相关阅读:
    10.异常
    9.1 oop习题集合
    9.抽象类和接口
    8.oop-多态
    AngularJs学习笔记二
    浅谈如何坚持计划
    妙味课堂——JavaScript基础课程笔记
    前端学习-试卷
    jquery实战
    boost any
  • 原文地址:https://www.cnblogs.com/buptmemory/p/2842754.html
Copyright © 2011-2022 走看看