废话少说,直接上代码
import os from os import path import operator def scaner_file(url): file = os.listdir(url) for f in file: real_url = path.join(url, f) if path.isfile(real_url): if operator.contains(f, "lhj002"): print(real_url) print(real_url.replace("002", "004")) os.rename(real_url, real_url.replace("001", "002")) elif path.isdir(real_url): # 如果是目录,则是地柜调研自定义函数 scaner_file (url)进行多次 scaner_file(real_url) else: print("其他情况") pass if __name__ == '__main__': scaner_file("D:\\zTools")
标签:重命名,文件,url,__,scaner,file,real,path From: https://www.cnblogs.com/dbasupport/p/16844302.html