;
; NT/95 delete files older then specified number of days - Kixtart 3.62, 3.63, 4.00
;
; (c) drillsergeant, mca - 2001
;
; vs 1.01 - program
;
; 1.00 (20010115) original version
; 1.01 (20010401)
;
CLS
BREAK on
FLUSHKB
MD "c:\temp" IF (Len(@wksta) <> 0)
$wksta=@wksta
ELSE
$wksta="unknown"
ENDIF
; ---------------------------------------------------------------------------
; - site defined settings -
; ---------------------------------------------------------------------------
$debug_mode="yes" ; - yes/no -
$debug_file="c:\temp\deletion_debug.txt" ; - c:\temp\deletion_debug.txt = file
; - CON = means output to user screen
$days = 7 ; - delete files older than specified number of days -
$log_file="c:\temp\deletion_"+$wksta+".log" ; - append to this file -
$max_directories=2
DIM $remove_dir[$max_directories+1]
$remove_dir[1] = "c:\test1"
$remove_dir[2] = "c:\test2"
; ---------------------------------------------------------------------------
; - main program by DrillSergeant / MCA -
; ---------------------------------------------------------------------------
$temp_file="c:\temp\deletion.tmp"
$log_file=LCASE($log_file)
;
IF ($debug_mode = "yes")
DEL $debug_file
IF ReDirectOutput($debug_file)
ENDIF
ENDIF
; ---------------------------------------------------------------------------
; - Here you control whether files in subdirectories should be
; - or excluded, with the switch "/s".
; - The "/b" switch stands for "base notation", (which excludes
; - everything but the filename), don't change this one!
; ---------------------------------------------------------------------------
GOSUB "calculate_date"
?
IF Open(2,"$log_file",5)
ENDIF
;
$count_skipped=0
$count_delete=0
;
$i = 1
WHILE ($i <= $max_directories)
IF Close(1)
ENDIF
DEL $temp_file
? "check directory '"+$remove_dir[$i]+"'"
$command = '%comspec% /c dir "'+$remove_dir[$i]+'" /s /b >'+$temp_file
SHELL $command
IF (Open(1,$temp_file,2) = 0)
$line = ReadLine(1)
WHILE @error = 0
GOSUB "check_file"
$line = ReadLine(1)
LOOP
ENDIF
$i = $i + 1
LOOP
IF Close(1)
ENDIF
IF Close(2)
ENDIF
IF (Exist($temp_file) = 1)
DEL $temp_file
ENDIF
IF ReDirectOutput("CON")
ENDIF
? "Informative DELETION: process completed. "+
$count_delete+" files deleted + "+
$count_skipped+" files skipped."
?
? "directories checked: "
$i=1
WHILE ($i <= $max_directories)
? " '"+$remove_dir[$i]+"'"
$i=$i+1
LOOP
IF ($debug_mode = "yes")
? "debug output: '"+$debug_file+"'"
ENDIF
EXIT
; ------------------------------------------------------------------------
; - calculate the date (minus $days) by DrillSergeant - -
; ------------------------------------------------------------------------
:calculate_date
$cury = @year
$curm = @monthno
$curd = @mdayno
IF $curm < 3
$curm = $curm + 12
$cury = $cury - 1
ENDIF
$curint = $curd + ( 153 * $curm - 457 ) / 5 + 365 * $cury + $cury / 4 - $cury / 100 + $cury / 400 - 306
$myz = $curint - $days + 306
$myh = 100 * $myz - 25
$mya = $myh / 3652425
$myb = $mya - $mya / 4
$rd_year = (100 * $myb + $myh) / 36525
$myc = $myb + $myz - 365 * $rd_year - $rd_year / 4
$rd_month = (5 * $myc + 456) / 153
$rd_day = $myc - (153 * $rd_month - 457) / 5
IF $rd_month > 12
$rd_year = $rd_year + 1
$rd_month = $rd_month - 12
ENDIF
IF Len("$Rd_Month") = 1
$rd_month = "0" + "$Rd_Month"
ENDIF
IF Len("$Rd_Day") = 1
$rd_day = "0" + "$Rd_Day"
ENDIF
$compare_date = "$Rd_Year/$Rd_Month/$Rd_Day"
;
IF ($debug_mode = "yes")
? "days "+$days
? "current date "+@date
? "compare date "+$compare_date
ENDIF
RETURN
; ------------------------------------------------------------------------
; - check file for yes/no for deletion by DrillSergeant / MCA -
; ------------------------------------------------------------------------
:check_file
$time = GetFileTime($line)
IF ($time > "")
IF (Substr($time,1,10) < $compare_date)
$log_info=@date+" "+@time+" delete '"+$line+"'"+
" ("+GetFileTime($line)+
" size="+GetFileSize($line)+
" older "+$days+" days)"
IF WriteLine(2,$log_info+Chr(13)+Chr(10))
ENDIF
IF ($debug_mode = "yes")
? $log_info
ELSE
DEL $line ; <--------------------- delete files ------
ENDIF
$count_delete=$count_delete+1
ELSE
$log_info=" -skip- '"+$line+"'"
IF ($debug_mode = "yes")
? $log_info
ENDIF
$count_skipped=$count_skipped+1
ENDIF
ENDIF
RETURN