cacd2000_split_identities.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import shutil
  2. import argparse
  3. import os
  4. import sys
  5. def main(args):
  6. src_path_exp = os.path.expanduser(args.src_path)
  7. dst_path_exp = os.path.expanduser(args.dst_path)
  8. if not os.path.exists(dst_path_exp):
  9. os.makedirs(dst_path_exp)
  10. files = os.listdir(src_path_exp)
  11. for f in files:
  12. file_name = '.'.join(f.split('.')[0:-1])
  13. x = file_name.split('_')
  14. dir_name = '_'.join(x[1:-1])
  15. class_dst_path = os.path.join(dst_path_exp, dir_name)
  16. if not os.path.exists(class_dst_path):
  17. os.makedirs(class_dst_path)
  18. src_file_path = os.path.join(src_path_exp, f)
  19. dst_file = os.path.join(class_dst_path, f)
  20. print('%s -> %s' % (src_file_path, dst_file))
  21. shutil.copyfile(src_file_path, dst_file)
  22. def parse_arguments(argv):
  23. parser = argparse.ArgumentParser()
  24. parser.add_argument('src_path', type=str, help='Path to the source directory.')
  25. parser.add_argument('dst_path', type=str, help='Path to the destination directory.')
  26. return parser.parse_args(argv)
  27. if __name__ == '__main__':
  28. main(parse_arguments(sys.argv[1:]))