CommunityScripts icon indicating copy to clipboard operation
CommunityScripts copied to clipboard

[renamerOnUpdate] Remove empty parent folders

Open 8ullyMaguire opened this issue 10 months ago • 0 comments

This could be made to remove all empty parent folders instead of just the current one.

https://github.com/stashapp/CommunityScripts/blob/468e9df869de39121acbb875abadf9785c627d1a/plugins/renamerOnUpdate/renamerOnUpdate.py#L1174-L1183

def remove_empty_parent_folders(path):
    # Walk the directory tree in reverse order (bottom-up)
    for root, dirs, files in os.walk(path, topdown=False):
        # If the directory is empty, try to remove it
        if not files and not dirs:
            try:
                os.rmdir(root)
                print(f"Removed empty directory: {root}")
            except OSError as e:
                print(f"Failed to remove directory {root}: {e}")
                
if REMOVE_EMPTY_PARENT_FOLDERS:
    remove_empty_parent_folders(current_dir)

8ullyMaguire avatar Apr 25 '24 11:04 8ullyMaguire