import os import shutil ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) IMAGES_DIR = os.path.join(ROOT_DIR, "images") STASH_NAME = "Stash" if os.path.isdir(IMAGES_DIR): for folder in os.listdir(IMAGES_DIR): if folder != STASH_NAME: shutil.rmtree(os.path.join(IMAGES_DIR, folder), ignore_errors=True)