代码:
import os import shutil def copy_and_rename_en_srt_files(parent_directory): # 遍历指定的父目录及其所有子目录 for root, dirs, files in os.walk(parent_directory): for file in files: # 检查文件是否以 .en.srt 结尾 if file.endswith('.en.srt'): # 获取文件的完整路径 file_path = os.path.join(root, file) # 构造新文件名,在原文件名前加上"zhong" new_file_name = "zhong" + file # 获取新文件的完整路径 new_file_path = os.path.join(root, new_file_name) # 复制文件 shutil.copy2(file_path, new_file_path) print(f"Copied and renamed '{file_path}' to '{new_file_path}'") # 指定你想要复制并重命名文件的文件夹路径 parent_directory_path = 'path_to_your_directory' copy_and_rename_en_srt_files(parent_directory_path)
标签:重命名,en,srt,复制,文件夹,file,new,directory,path From: https://www.cnblogs.com/jingzaixin/p/18158894