import os import shutil # 定义源目录和目标目录 source_dir = "/Users/sysadmin/code/wb_project/2025_02_12_shanghai-aiyun-information/123" target_dir = "/Users/sysadmin/code/wb_project/2025_02_12_shanghai-aiyun-information/docs" # 创建目标文件夹(如果不存在) if not os.path.exists(target_dir): os.makedirs(target_dir) # 遍历所有文件并移动符合条件的文件 for root, dirs, files in os.walk(source_dir): for file in files: if file.endswith(('.txt', '.csv', '.xlsx', '.xls')): source_file = os.path.join(root, file) target_file = os.path.join(target_dir, file) shutil.move(source_file, target_file) print("文件移动完成!")