ift_backup.py 793 B

1234567891011121314151617181920212223242526
  1. import os
  2. from pathlib import Path
  3. def ift_backup(base_dir=None):
  4. if base_dir is None:
  5. base_dir = '/home/robert/projekte/python/BMW_Wien/IFT'
  6. source_path = Path(base_dir) / 'prod'
  7. target_path = base_dir + '/archive'
  8. for source_file in source_path.glob('*.txt'):
  9. # print(source_file)
  10. file_temp = source_file.name[:-4]
  11. if file_temp.count('_') == 2:
  12. prefix, filetype, timestamp = file_temp.split('_')
  13. year = timestamp[:4]
  14. month = timestamp[4:6]
  15. target = f"{target_path}/{filetype}/{year}/{year}-{month}/{source_file.name}"
  16. os.makedirs(Path(target).parent, exist_ok=True)
  17. print(target)
  18. # source_file.rename(target)
  19. if __name__ == '__main__':
  20. ift_backup()