python选定指定类型的文件复制到其他文件夹
#-*- codeing =utf-8 -*- #@Time : 2022/7/1 22:53 #@Author : huaobin #@File : testcopy.py #@Software: PyCharm import os import shutil def copy_allfiles(src,dest): #src:原文件夹;dest:目标文件夹 src_files = os.listdir(src) for file_name in src_files: print(file_name) if '.xml' in file_name: full_file_name = os.path.join(src, file_name) if os.path.isfile(full_file_name): shutil.copy(full_file_name, dest) copy_allfiles(r'.\labels',r'.\copy')