Feature Request: Prune Empty/Unused TV Recording Directories

Hello,

This would be a 'nice to have' feature - "Prune Empty Directories"

When Channels records something, it creates a directory using the name of the recorded program at the file system level. I.e. -

However, if/when you delete, from the web admin, whatever it was you recorded, it doesn't cleanup after itself and remove the empty directory at the filesystem level.

I realize these empty directories don't take up any space, but if you're manually going through your drive cleaning things up, you have to enter each directory to see if it is actually empty before deleting it; and then of course you go back into the CDVR admin and run "Prune Removed Media".

Cheers!

If you want to manage your empty directories in a less manual way, there are many tools out there to automate it for you.

We see no reason to delete directories that are most likely going to just be recreated a week later when the next recorded episode comes in. So there’s no plans for us to do this.

Must depend on the OS Channels DVR runs on.
When I trash and delete the last recording in a TV Show (from within Channels DVR), it removes the TV Show folder from the disk. Synology NAS, both native package and docker containers.

Only things I can think of that could prevent Channels DVR from deleting the folder are;
a) The directory isn't empty (perhaps a hidden file in there)
b) The user Channels DVR runs as doesn't have delete rights for the directories under TV/
c) Software (anti-virus/anti-malware) is preventing it

It always deletes the folder when I delete the last show or all shows from the Gui at least it does this on Windows.... when trash is emptied so is the folder.

That's only for local content imports, not things recorded by Channels DVR.

Are you pointing Plex to the Channels DVR recordings? because. grab is a Plex temp folder.

Yeah, I'm not sure what @maddox is saying because empty folders for Channels recording do automatically delete for me (Windows). However, empty folders for personal media and stream links do not.

@ChannelRat, here's a bit of Python code that can remove the empty directories for you:

import os

# Remove empty subdirectories without prompting
def directory_delete(base_directory):
    for root, dirs, _ in os.walk(base_directory, topdown=False):
        for dir_name in dirs:
            dir_path = os.path.join(root, dir_name)
            if not os.listdir(dir_path):
                os.rmdir(dir_path)
                print(f"    Removed empty directory: {dir_path}")

base_directory = "YOUR_CHANNELS_DIRECTORY_HERE"
directory_delete(base_directory):

I was talking about imports, but I used the word recorded in error.

Well, it looks like @chDVRuser solved the mystery. It turns out there is a hidden directory named "@eaDir" in every directory. Which turns out to be from Synology's indexing service and apps like Synology Photos. So thanks, mystery solved! Or at least as to why the directories aren't being deleted.

I tried excluding the directories from the indexing service, but after running a quick test, it still created that hidden folder. I'm not sure why and doubt I'll spend much more time on it now that I seem to understand what's happening.

@babsonnexus - I'll never turn down simple scripts. It has been dutifully added to my script collection. Thanks!

1 Like