import os def get_subdirectories(root_dir, max_depth=2): directories = [] for root, dirs, _ in sorted(os.walk(root_dir)): if root == root_dir: continue # Skip the root directory itself depth = root[len(root_dir):].count(os.sep) if depth < max_depth: directories.append(root) else: del dirs[:] # Stop descending further return directories def load_files(ad): valid_extensions = {"tiff", "tif", "png", "jpg", "jpeg", "bmp", "gif", "webp"} # Common image formats FileNames = [] for file in sorted(os.listdir(ad)): try: if file.split(".")[-1].lower() in valid_extensions: FileNames.append(file) except IndexError: pass return sorted(FileNames)