标签:ret dia not app end imp 完整路径 文件夹 div
1.遍历文件夹下所有文件
2.将后缀为.DCM的文件复制到指定文件夹
import os import shutil def all_path(dirname): result = []#所有的文件 for maindir, subdir, file_name_list in os.walk(dirname): # print("1:",maindir) #当前主目录 # print("2:",subdir) #当前主目录下的所有目录 # print("3:",file_name_list) #当前主目录下的所有文件 if len(subdir) == 0 and len(file_name_list) < 5: for filename in file_name_list: apath = os.path.join(maindir, filename)#合并成一个完整路径 result.append(apath) elif len(subdir) > 0: for filename in file_name_list: apath = os.path.join(maindir, filename) # 合并成一个完整路径 result.append(apath) else: continue return result def copy(all_list): new_path = r‘/media/awifi/40FD960833674C19/workspace/示范区柯桥确诊/DR_FOR_TEST‘ for i in all_list: if not i.endswith(‘.DCM‘): continue else: print(i) name = os.path.basename(i) new_name = new_path + ‘/‘ + name shutil.copyfile(i, new_name) if __name__ == ‘__main__‘: result = all_path("/media/awifi/40FD960833674C19/workspace/示范区柯桥确诊/DR") copy(result)
标签:ret dia not app end imp 完整路径 文件夹 div
原文地址:https://www.cnblogs.com/weihuang6620/p/11508102.html