| import os |
| import shutil |
| import argparse |
|
|
| def get_filenames_without_extension(directory, extension): |
| return set([os.path.splitext(f)[0] for f in os.listdir(directory) if f.endswith(extension)]) |
|
|
| def move_unmatched_files(image_dir, text_dir, unmatched_dir, image_ext='.png', text_ext='.txt'): |
| |
| if not os.path.exists(unmatched_dir): |
| os.makedirs(unmatched_dir) |
|
|
| |
| image_files = get_filenames_without_extension(image_dir, image_ext) |
| text_files = get_filenames_without_extension(text_dir, text_ext) |
|
|
| |
| unmatched_images = image_files - text_files |
|
|
| |
| for image in unmatched_images: |
| shutil.move(os.path.join(image_dir, image + image_ext), |
| os.path.join(unmatched_dir, image + image_ext)) |
|
|
| def main(): |
| parser = argparse.ArgumentParser(description='Move unmatched image files to a separate directory.') |
| parser.add_argument('image_dir', type=str, help='Directory containing image files.') |
| parser.add_argument('text_dir', type=str, help='Directory containing text files.') |
| parser.add_argument('unmatched_dir', type=str, help='Directory to move unmatched image files to.') |
| args = parser.parse_args() |
|
|
| move_unmatched_files(args.image_dir, args.text_dir, args.unmatched_dir) |
|
|
| if __name__ == "__main__": |
| main() |
|
|