import os
def ModifyFileName(filepath, originalname, modifyname):
filename = os.path.basename(filepath)
if originalname in filename:
replacename = filename.replace(originalname, modifyname)
replacepath = os.path.dirname(filepath)+'\'+replacename
try:
os.rename(filepath, replacepath)
print(filename + " 已修改为:" + replacename)
except :
print(filename + "文件路径不存在")
def ModifyAll(dirpath, originalname, modifyname):
for root, dirs, files in os.walk(dirpath):
for file in files:
ModifyFileName(os.path.join(root, file),originalname,modifyname)
print("已全部修改")
if __name__ == '__main__':
dirpath = "文件夹路径"
originalname = "需要修改的部分"
modifyname = "更改后的内容"
print("正在执行中")
ModifyAll(dirpath, originalname, modifyname)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)