2005-12-16, 12:12 PM
I am trying to make a small batch file that automatically purge excess recordings when the HDD fills up.
It uses a purge.ini file to specify what should be deleted
The first item on each line specifies a dir mask used to define a group of recordings. The second item is the maximum number of recordings matching the file mask that should be kept.
The last line specifies that no more then 20 recordings should be kept in total
The purge.bat file reads the purge.ini file and processes each line
The oldest files matching the mask exceeding the count are deleted with a wildcard as extension mask.
purge.ini should be in the directory that should be purge.
purge.bat should be executed in the directory to be purged
A simple way to do this is to copy both files (of course you have to change purge.ini to your situation) into the directory that should be purged and to use a scheduled task to run purge.bat
For testing purposes it is recommended to manually execute purge and to put a 'rem' before the Del and to write the output to a log file as
purge >purge.log
I am still looking for an easy way to determine the amount of free space from a bat dos batch file so I can use that to delete old recorsdings i.s.o. using a maximum number of recordings.
Usual disclaimer: Use this at your own risk, this script can do terrible things
A zip file containing the two purge files can be downloaded from here
It uses a purge.ini file to specify what should be deleted
Code:
close*.mpg 1
star*.mpg 0
crime*.mpg 2
*.mpg 20
The last line specifies that no more then 20 recordings should be kept in total
The purge.bat file reads the purge.ini file and processes each line
The oldest files matching the mask exceeding the count are deleted with a wildcard as extension mask.
Code:
@Echo off
for /F "usebackq tokens=1,2" %%i in ("purge.ini") do call :processline "%%i" "%%j"
goto :eof
:processline
Echo .
Echo Rule : %1 %2
Echo -------------------------
dir/o:-d/b %1 >purge.lst
set/A counter=0
for /F "usebackq tokens=1,2" %%k in ("purge.lst") do call :processfile "%%k" %%2 %%1
del/q purge.lst
goto :eof
:processfile
set/A level=%2
if %counter% GEQ %level% call :purgefile %1
if %counter% LSS %level% echo Keep: "%~dpn1.*"
set/A counter=counter+1
goto :eof
:purgefile
echo Purge: "%~dpn1.*"
Del/q "%~dpn1.*"
goto :eof
:eof
purge.ini should be in the directory that should be purge.
purge.bat should be executed in the directory to be purged
A simple way to do this is to copy both files (of course you have to change purge.ini to your situation) into the directory that should be purged and to use a scheduled task to run purge.bat
For testing purposes it is recommended to manually execute purge and to put a 'rem' before the Del and to write the output to a log file as
purge >purge.log
I am still looking for an easy way to determine the amount of free space from a bat dos batch file so I can use that to delete old recorsdings i.s.o. using a maximum number of recordings.
Usual disclaimer: Use this at your own risk, this script can do terrible things
A zip file containing the two purge files can be downloaded from here
P4 3GHz 1GB, 250GB, nVidia dualTV, GBPVR 1.3.11, XP
Support Comskip, visit the forum and donate at http://www.comskip.org/
Support Comskip, visit the forum and donate at http://www.comskip.org/