|
import os |
|
import shutil |
|
|
|
def copy_images(source_dir, dest_dir): |
|
|
|
if not os.path.exists(dest_dir): |
|
os.makedirs(dest_dir) |
|
|
|
|
|
for root, _, files in os.walk(source_dir): |
|
for filename in files: |
|
print(filename) |
|
source_file = os.path.join(root, filename) |
|
|
|
|
|
folder_name = os.path.basename(root) |
|
|
|
new_filename = f"{folder_name}_{filename}" |
|
dest_file = os.path.join(dest_dir, new_filename) |
|
|
|
|
|
if os.path.isfile(source_file) and not os.path.exists(dest_file): |
|
shutil.copy2(source_file, dest_file) |
|
print(f"Copied: {new_filename}") |
|
else: |
|
print(f"Skipped: {filename} (already exists or not a file)") |
|
|
|
def main(): |
|
|
|
source_directory = '../categorised-images' |
|
destination_directory = '../original-images' |
|
|
|
|
|
copy_images(source_directory, destination_directory) |
|
|
|
if __name__ == "__main__": |
|
main() |