批量修改文件扩展名称

#写个小程序,把tmp的扩展文件名修改为tttmmmppp

import os
import sys
import re

os.system("where /R e:\ *.tmp > tmp.txt")

f_an=file("e:\tmp.txt")

while True:    
        line=f_an.readline()
        line=line.replace('\n',' ')
        aList = os.path.split(os.path.realpath(line))
        
        path=aList[0]
        cmd="ren "+aList[0]+"\\"+aList[1]+" "+aList[1].replace('.tmp','.tttmmmppp')
        print cmd
        os.system(cmd)
        if len(line)==0: # Zero length indicates EOF
            break

f_an.close()

猜你喜欢

转载自blog.csdn.net/baidu_38316985/article/details/81291297