I use Plex to watch TV shows recorded by NextPVR. When done with the recordings, I will delete them via Plex. This leaves behind orphaned metadata. I wanted a routine to clean up the NextPVR recordings folder, delete orphaned NextPVR metadata and if that leaves an empty folder, delete the empty folder as well. So, I asked AI to help me create a batch file to perform these duties. I then set a task in Windows Task Scheduler to run this batch file daily. Below is the batch file created with the help of AI. Please note that you use this batch file AT YOUR OWN RISK. Please backup your recordings folder before applying this process. It WILL delete any files that do not have a related file with a .ts file extension. If there is a .ts file, it will leave it and its associated metadata alone. If you have any .mp4's for instance in the NextPVR recordings folder, they will also be deleted since they have no .ts file associated with them. This script assumes that you use the NextPVR recordings folder only for NextPVR recordings with the .ts file extension. Please replace the set command at the beginning to point to YOUR recordings folder. What you see is mine as an example. Do not put this batch file in the recordings folder itself for it will delete itself. No warranty is implied, use at your own risk. You can copy and paste into your favorite text editor. Make the set command change to reflect your recordings folder and save as a batch (.bat) file. Again, do NOT place the batch file in the recordings folder....
@echo off
set "folder_path=D:\Recorded TV\"
for /r "%folder_path%" %%F in (*) do (
if "%%~xF" neq ".ts" (
if not exist "%%~dpnF.ts" (
del "%%F"
echo Delete: "%%F"
)
)
)
for /d /r "%folder_path%" %%d in (*) do (
dir /b "%%d" 2>nul | findstr "^" >nul || (
rd "%%d"
echo Deleted empty subfolder: "%%d"
)
)
@echo off
set "folder_path=D:\Recorded TV\"
for /r "%folder_path%" %%F in (*) do (
if "%%~xF" neq ".ts" (
if not exist "%%~dpnF.ts" (
del "%%F"
echo Delete: "%%F"
)
)
)
for /d /r "%folder_path%" %%d in (*) do (
dir /b "%%d" 2>nul | findstr "^" >nul || (
rd "%%d"
echo Deleted empty subfolder: "%%d"
)
)