对比提取独有目录.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : 对比提取独有目录.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2023/1/6
  6. import os
  7. import shutil
  8. from time import time
  9. def getDirLists(path):
  10. files = os.listdir(path)
  11. print(len(files),files)
  12. return files
  13. def get_extra(list1,list2):
  14. extra_list = set(list1) ^ set(list2)
  15. extra_list = list(extra_list)
  16. print(len(extra_list),extra_list)
  17. return extra_list
  18. def get_interval(t):
  19. interval = time() - t
  20. interval = round(interval*1000,2)
  21. return interval
  22. def copy_extra(compare_path,to_path,extra_list):
  23. t1 = time()
  24. total = len(extra_list)
  25. dir_total = 0
  26. for i in range(total):
  27. extra = extra_list[i]
  28. file_from = os.path.join(compare_path, extra)
  29. if os.path.isdir(file_from): # 判断是否为文件夹
  30. dir_total += 1
  31. file_to = os.path.join(to_path, extra)
  32. print(f'开始提取第{i+1}/{total}项,复制{file_from}到{file_to}...')
  33. shutil.copytree(file_from, file_to, dirs_exist_ok=True)
  34. else:
  35. print(f'跳过提取非文件夹:{file_from}')
  36. # break
  37. print(f'全部文件夹提取完毕,共计{total}项,{dir_total}个文件夹,耗时{get_interval(t1)}毫秒')
  38. if __name__ == '__main__':
  39. base_path = r'F:\odoo模块\odoo16c\addons'
  40. compare_path = r'F:\odoo模块\odoo16e20221019\odoo\addons'
  41. to_path = r'F:\odoo模块\odoo16ec\addons'
  42. base_files = getDirLists(base_path)
  43. compare_files = getDirLists(compare_path)
  44. extra_list = get_extra(base_files,compare_files)
  45. copy_extra(compare_path, to_path, extra_list)