Download MEDIA/scripts/remove_empty_dirs.py from pebxcvi/PSHomeCacheDepot: direct link, hf CLI and curl.
- Browser
- Download file 895 Bytes
-
https://huggingface.co/datasets/pebxcvi/PSHomeCacheDepot/resolve/c4e4ad14b7fa0df35b7955ea8d9b93157a2d3037/MEDIA/scripts/remove_empty_dirs.py
- Command line
-
hf download hf://datasets/pebxcvi/PSHomeCacheDepot@c4e4ad14b7fa0df35b7955ea8d9b93157a2d3037/MEDIA/scripts/remove_empty_dirs.py
-
curl -L -o remove_empty_dirs.py https://huggingface.co/datasets/pebxcvi/PSHomeCacheDepot/resolve/c4e4ad14b7fa0df35b7955ea8d9b93157a2d3037/MEDIA/scripts/remove_empty_dirs.py
895 Bytes
| import os | |
| def remove_empty_dirs(directory): | |
| """ | |
| Recursively removes empty directories and subdirectories. | |
| Args: | |
| - directory: The root directory from which to start removing empty directories. | |
| """ | |
| # Check each directory and subdirectory | |
| for subdir in os.listdir(directory): | |
| full_subdir_path = os.path.join(directory, subdir) | |
| if os.path.isdir(full_subdir_path): | |
| remove_empty_dirs(full_subdir_path) | |
| # After checking subdirectories, try to remove the parent directory | |
| try: | |
| os.rmdir(directory) | |
| print(f"Removed empty directory: {directory}") | |
| except OSError as e: | |
| # Directory not empty | |
| pass | |
| if __name__ == "__main__": | |
| current_directory = os.getcwd() | |
| media_directory = os.path.join(current_directory, "ARCHIVE") | |
| remove_empty_dirs(media_directory) | |
| input("") |