Last active
May 16, 2022 11:01
-
-
Save nico-i/61765334ab3dd56e35d8c1d2f54567e9 to your computer and use it in GitHub Desktop.
Copy nested images into an output directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import sys | |
from tqdm import tqdm | |
work_path = '.' | |
if len(sys.argv) > 1: | |
work_path = sys.argv[1] | |
output_dir = os.path.abspath('./all_files/') | |
if len(sys.argv) > 2: | |
output_dir = sys.argv[2] | |
new_files_name = 'IMG' | |
if len(sys.argv) > 3: | |
new_files_name = sys.argv[3] | |
script_file_name = os.path.basename(__file__) | |
file_counter = 1 | |
copy_tuples = [] | |
if not os.path.exists(output_dir): | |
os.makedirs(output_dir) | |
for root, dirs, files in os.walk(work_path): | |
if script_file_name in files or output_dir == os.path.abspath(root): | |
continue | |
for file in files: | |
base_name, extension = os.path.splitext(file) | |
if extension not in ['.jpeg', '.jpg', '.png', '.gif', '.tiff', '.RAW', '.ARW']: | |
continue | |
new_file_path = os.path.join( | |
output_dir, new_files_name + '_' + str(file_counter) + extension) | |
copy_tuples.append((os.path.join(root, file), new_file_path)) | |
file_counter += 1 | |
for copy_tuple in tqdm(copy_tuples, desc='Copying files: '): | |
shutil.copy(copy_tuple[0], copy_tuple[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment