Scankill

Scankill

From TeleFlow

Jump to: navigation, search

Scankill is a batch program that uses FI.exe (locate on net) to scan a specified directory tree for file that are of a certain age and/or size

@echo off
rem  engenic 2004
rem  -- Used to find and remove log files and other files that are old and need to
rem  -- or archived
rem  Free software... Use as is... No warranties
 
rem - No parameters goes to help
if "%2" == "" goto help
 
rem - Invalid directory, goes to no files
if not exist %1 goto nofiles
 
rem === Determine if we are to do anything ===
set skdays=999
set sktype=0
set skdir=%1
if "%2" == "wav"   set sktype=1
if "%2" == "log"   set sktype=2
if "%2" == "nhlog" set sktype=3
if "%2" == "tflog" set sktype=4
if "%2" == "bak"   set sktype=5
 
 
rem =============================
rem === Set up the parameters ===
rem =============================
rem ::: Make changes as needed
if %sktype%==1 set skdays=90
if %sktype%==2 set skdays=45
if %sktype%==3 set skdays=14
if %sktype%==4 set skdays=7
if %sktype%==5 set skdays=90
 
rem ::: Make changes as needed
if %sktype%==1 set skfilepat=*.wav
if %sktype%==2 set skfilepat=*.log
if %sktype%==3 set skfilepat=TF?e*.log
if %sktype%==4 set skfilepat=TFVO*.log
if %sktype%==5 set skfilepat=*.bak
 
if %skdays%==999 goto help
goto scan
 
 
:help
echo Command Usage:
echo "Scankill dir type[wav|log|bak|nhlog|tflog] [KILL]"
echo   dir   : The directory to scan.  Use a dot '.' for current dir
echo   type  : The file type to remove
echo   - nhlog = TFNetHub log files
echo   - tflog = TeleFlow Appliation log files
echo   KILL  : Add the KILL flag to delete the files immediately (use with caution)
echo .
echo Note: Requires fi.exe
goto final
 
:scan
echo Scanning...
 
REM ======= Get Date Parts =======
FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :s_fixdate %%G %%H %%I %%J)
goto :s_print_the_date
:s_fixdate
if "%1:~0,1%" GTR "9" shift
FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (
    set %%G=%1&set %%H=%2&set %%I=%3)
goto :eoff
:s_print_the_date
rem echo Month:[%mm%]  Day:[%dd%]  Year:[%yy%]
ENDLOCAL&SET mm=%mm%&SET dd=%dd%&SET yy=%yy%
 
 
REM ======= Set Filenames =======
echo Files %skdir%\%skfilepat% older than %skdays% days
set skfilecmd=scankill-%yy%-%mm%-%dd%-%2.cmd
set skfiletmp=scankill-%yy%-%mm%-%dd%-%2.tmp
set skfiletxt=scankill-%yy%-%mm%-%dd%-%2.txt
 
 
REM ======= Do the Scan =======
fi /s /b "/g>%skdays%" %skdir%\%skfilepat% > %skfiletmp%
if errorlevel 1 goto nofiles
 
 
echo Creating kill file...
if exist %skfilecmd% del %skfilecmd%
echo rem Scankill has indicated these files (%skdir%\%skfilepat%) are older than %skdays% old > %skfilecmd%
echo rem They should be deleted with the following commands >> %skfilecmd%
echo rem >> %skfilecmd%
FOR /F "delims=~" %%f in (%skfiletmp%) DO echo del "%%f" >> %skfilecmd%
 
if "%3" == "KILL" goto killnow
echo .
echo Run the following command to remove files...
echo %skfilecmd%
echo .
goto end
 
:killnow
echo Killing files now...
%skfilecmd%
goto end
 
:nofiles
echo No files were found that needed to be removed
 
:end
del %skfiletmp%
echo done
 
:final
:eoff


You can run several scankills together to clean up a drive in a fairly automatic fashion. For example, create a batch called masterscankill.cmd and populate it like this (for example)

rem - Do a wide scan of the system for old files
rem - NOTE: You decide if you trust this enough to add the "KILL" switch.
rem --- for help on scankill ... type it with no parameters
rem --- the ping is a 5 second pause
 
start /b  scankill "C:\Program Files\enGenic\TFNetHub\Log" nhlog
@ping 127.0.0.1 -n 5 -w 1000 > nul
start /b  scankill "C:\TFVO\log" tflog
@ping 127.0.0.1 -n 5 -w 1000 > nul
start /b  scankill "C:\dictation\host\TFApps\Dictation\Vmail\Volume0000000001" wav
 
dir scankill*.cmd


When you run it, nothing will be deleted. the three scankill calls internally will create (for example) these files:

  • scankill-2008-01-30-nhlog.cmd
  • scankill-2008-01-30-tflog.cmd
  • scankill-2008-01-30-wav.cmd

The contain the commands to remove the old files. The idea is that the master will create the files which can be run manually, and become the log files as well. After running the command a few times, and you are comfortable with the files running automatically, add KILL to the end to save the step of having to manually run them.

eg:

start /b scankill "C:\TFVO\log" tflog

becomes

start /b scankill "C:\TFVO\log" tflog KILL

In this way, masterscankill can be set up as a standard routine for preventative maintenance off any application.