defsearchFile(src_dir, ext_filters, result_list): ifnot os.path.exists(src_dir) ornot os.path.isdir(src_dir): print('None exits folder or not a directory at all, for:', src_dir, 'and will be ignored!') return for file in os.listdir(src_dir): file = os.path.join(src_dir, file) if os.path.isfile(file) and os.path.splitext(file)[1] in ext_filters: result_list.append(file) elif os.path.isdir(file): searchFile(file, ext_filters, result_list)
# 修改这里为你的文件夹路径 defgetInputWorkDirectories(): dirs = [] # 你的文件夹路径,绝对路径,可以不写 use_default = input('Use default directories?(y/n):') if use_default notin ['n', 'no', 'NO', 'N']: return dirs path = input('Input the work directory(0 char to stop):') dirs = [path] while len(path) > 1: path = input('Input the work directory(0 char to stop):') dirs.append(path) return dirs
defstartWork(): gene = createGeneratedFolder() dirs = getInputWorkDirectories() if len(dirs) == 0: return extensions = getInputExtensions() # 方法已省略,返回扩展名数组 for d in dirs: files = getSearchedFiles(d, extensions) for f in files: copySingleFile(f, gene)
if __name__ == '__main__': print('Start working......') startWork() print('Done!')