Pythonを使用して指定されたディレクトリファイルの名前を変更する

Pythonを使用して指定されたディレクトリファイルの名前を変更する

1.  [ファイル] 指定したディレクトリファイルの名前を変更します ~ 715B

 #Copyright 2012 wuyuangui.
  #www.iplaypy.com python教程
 
import os
 
path = 'F:\Python\open project\SGI\SGI_STL'
paths = path.replace('\\', '//')
paths = paths + '//'
print paths
files = os.listdir(paths)
for i in files:
    #print(i)
    pat = None
    pat = paths + str(i)
    if os.path.isdir(pat):
        pass
    elif os.path.isfile(pat):
        if not str(pat).endswith('.h'):
            list = pat.split('//')
            patt =  list[list.__len__() - 1] + '.h'
            print(str(i) + str(patt))
            os.rename(pat, str(pat + patt))
            #os.rename(str(pat + patt), pat)
                        
        print('regfile:' + pat)
    else:
        pass

おすすめ

転載: blog.csdn.net/lmrylll/article/details/132008263