import os from shutil import copy #将特定目录root_path下所有文件夹中的label.png文件复制到 指定路径to_path中并命名为”n.png“ #添加root_path root_path = "root_path" files = os.listdir(root_path) #添加to_path to_path = "to_path" #文件名可以自行根据需要改 #filename = "*.png" filename = "label.png" for file in files: #使用file的命名 如文件名”1_person.png“ #则此处n为1 n = file.split('_')[0] with open(root_path+"\\"+file+"\\"+filename,"r") as f: copy(root_path+"\\"+file+"\\"+filename,to_path+"\\"+n+".png")
将指定目录下所有文件夹中特定文件复制到其他文件夹
最新推荐文章于 2023-08-01 09:36:16 发布