(source_dir, target_dir, file_extension='.pkl')
| 110 | |
| 111 | |
| 112 | def process_directory(source_dir, target_dir, file_extension='.pkl'): |
| 113 | os.makedirs(target_dir, exist_ok=True) |
| 114 | |
| 115 | pkl_files = [] |
| 116 | for root, _, files in os.walk(source_dir): |
| 117 | for file in files: |
| 118 | if file.endswith(file_extension): |
| 119 | full_path = os.path.join(root, file) |
| 120 | pkl_files.append(full_path) |
| 121 | |
| 122 | total_files = len(pkl_files) |
| 123 | print(f"Find {total_files} files!") |
| 124 | |
| 125 | for file_path in tqdm(pkl_files, desc="Processing"): |
| 126 | relative_path = os.path.relpath(file_path, source_dir) |
| 127 | output_path = os.path.join(target_dir, relative_path) |
| 128 | |
| 129 | os.makedirs(os.path.dirname(output_path), exist_ok=True) |
| 130 | |
| 131 | process_pkl_file(file_path, output_path) |
| 132 | |
| 133 | |
| 134 | if __name__ == "__main__": |
no test coverage detected