import os #文件在那个文件路径下 path = r'C:\Users\Administrator\Downloads\睡前故事3' # 获取该目录下所有文件,存入列表中 fileLists = os.listdir(path) #print(fileLists) #循环获取当前文件路径 for fileList in fileLists: print(fileList) paths = r'C:\Users\Administrator\Downloads\睡前故事3'+f'\{fileList}' print(paths) #循环改名 for inner_file in fileLists: # 获取旧文件名(就是路径+文件名) old_name = path + os.sep + inner_file # os.sep添加系统分隔符 print(old_name) if os.path.isdir(old_name): # 如果是目录则跳过 continue #查找乱码位置 index1 = inner_file.rfind("_") #查找最后需要修改文件位置 index2 = inner_file.rfind(".mp3") a = str(inner_file)[index1:index2] #替换字段 prefix = str(inner_file).replace(a,"")
文件名含有乱码改名
最新推荐文章于 2025-05-04 19:41:26 发布