~~~ #!/usr/bin/python script_outputs = './CleanAnimationsFolder' sorting_folder = './SortingFolder' import glob import os import shutil def get_matching_path(input_root, output_root, input_path): relpath = os.path.relpath(input_path, input_root) return os.path.join(output_root, relpath) def output_completed(output_path): if os.path.exists(f"{output_path}.lock"): return False if os.path.exists(output_path): return True base, ext = os.path.splitext(output_path) start = len(base) end = -len(ext) for candidate in glob(f"{base}*{ext}"): try: int(candidate[start:end]) return True except: pass return False prior_files = set() for root, dirs, files in os.walk(sorting_folder): for fn in files: prior_files.add(fn) for root, dirs, files in os.walk(script_outputs): for fn in files: if (fn == 'logs.txt') or (fn in prior_files): continue if fn.endswith('.lock'): continue source_path = os.path.join(root, fn) if not output_completed(source_path): continue dest_path = get_matching_path(script_outputs, sorting_folder, source_path) dest_folder = os.path.dirname(dest_path) print('copying', source_path, 'to', dest_path) os.makedirs(dest_folder, exist_ok=True) shutil.copyfile(source_path, dest_path) ~~~