Last active
May 16, 2024 13:29
-
-
Save jupiterbjy/2a57738217508cb3e302b897707511ed to your computer and use it in GitHub Desktop.
Some script to copy images to temp dir with same dir structure. Used to copy images only from clipstudio drawings folder.
This file contains 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 pathlib | |
import shutil | |
ROOT = pathlib.Path(__file__).parent | |
TEMP = pathlib.Path("X:/extemp") | |
TEMP.mkdir(exist_ok=True) | |
EXT_WHITELIST = {".webp", ".png", ".jpg", ".jpeg", ".apng", ".gif"} | |
def copy_to_temp(start_path, temp_path): | |
for path in start_path.iterdir(): | |
if path.name.startswith("_"): | |
continue | |
tmp_path = temp_path / path.name | |
if path.is_dir(): | |
tmp_path.mkdir(exist_ok=True) | |
copy_to_temp(path, tmp_path) | |
continue | |
if path.suffix in EXT_WHITELIST: | |
print(f"Copying {path} to {tmp_path}") | |
shutil.copyfile(path.as_posix(), tmp_path.as_posix()) | |
continue | |
try: | |
copy_to_temp(ROOT, TEMP) | |
finally: | |
import traceback | |
traceback.print_exc() | |
input("Press enter to exit") |
Author
jupiterbjy
commented
May 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment