zoukankan      html  css  js  c++  java
  • 批量重命名指定目录下的文件python

     1  #Copyright 2012 wuyuangui.
     2  #contact : notmycupoftea@163.com
     3  
     4 
     5 
     6 import os
     7 
     8 path = 'F:\Python\open project\SGI\SGI_STL'
     9 paths = path.replace('\\', '//')
    10 paths = paths + '//'
    11 print paths
    12 files = os.listdir(paths)
    13 for i in files:
    14     #print(i)
    15     pat = None
    16     pat = paths + str(i)
    17     if os.path.isdir(pat):
    18         pass
    19     elif os.path.isfile(pat):
    20         if not str(pat).endswith('.h'):
    21             list = pat.split('//')
    22             patt =  list[list.__len__() - 1] + '.h'
    23             print(str(i) + str(patt))
    24             os.rename(pat, str(pat + patt))
    25             #os.rename(str(pat + patt), pat)
    26                        
    27         print('regfile:' + pat)
    28     else:
    29         pass
  • 相关阅读:
    JQuery高级
    Filter&Listener
    关于用户信息的一个综合案例
    JSP,EL和JSTL
    Cookie和Session
    Request和Response
    Servlet和HTTP请求协议
    Tomcat
    xml
    数组模拟堆
  • 原文地址:https://www.cnblogs.com/lihuibng/p/2615080.html
Copyright © 2011-2022 走看看