Python3 代码优化:移动文件,避免覆盖同名文件
import shutil, os, re, sys
file_type = ('.m3u8') num = [0] new_path = r'E:\下载\ave' for derName, subfolders, filenames in os.walk(r'D:\用户目录\下载'): for i in range(len(filenames)): if filenames[i].endswith(file_type): file_path = derName + '/' + filenames[i] newpath = new_path + '/' + filenames[i] if not os.path.exists(newpath): # 判断文件是否存在 shutil.move(file_path, newpath) num[0] += 1 print('完成', num[0])
原文地址: https://www.cveoy.top/t/topic/nhue 著作权归作者所有。请勿转载和采集!