import os, os.path def read_dir(path, cpath, ftype): stack = list() stack.append(path) while len(stack): item = stack.pop() if os.path.isdir(item): for i in os.listdir(item): stack.append(os.path.join(item, i)) elif item.endswith(ftype): rfile = open(item, 'rb') c_path = os.path.join(cpath, os.path.basename(item)) wfile = open(c_path, 'wb') while True: contents = rfile.read(10 * 1024 * 1024) if not len(contents): break wfile.write(contents) rfile.close() wfile.close() def main(): # 文件来源 path = r"D:\Program Files\feiq\Recv Files" # 文件存放 cpath = r"C:\Users" # 需要筛选的文件类型 ftype = ".md" read_dir(path, cpath, ftype) if __name__ == '__main__': main()
从文件夹中提取某一类文件,实现思路栈
最新推荐文章于 2023-12-14 11:57:54 发布