用python批量修改文件名

 

import os
'''
huanglei 说
python 是世界上最好的语言 20240805 ''' def rename_file(old_name, new_name): os.rename(old_name, new_name) def get_filenames(directory): filenames = os.listdir(directory) return filenames if __name__ == '__main__': path = r"E:\weiChatFiles\WeChat Files\wxid_kd3gb4iuwkmf21\FileStorage\File\2024-08\jjwl" fileNames =get_filenames(r"E:\weiChatFiles\WeChat Files\wxid_kd3gb4iuwkmf21\FileStorage\File\2024-08\jjwl") for fileName in fileNames: print(fileName) newFileName = fileName.replace('20240802','20240805') print(newFileName) rename_file(path+'\\'+fileName,path+'\\'+newFileName)

 

posted @ 2024-08-06 17:15  huanglei2010  阅读(5)  评论(0编辑  收藏  举报