main.py 718 B

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