Biterscript to delete all files > 14 days old

Closed
acidburn - May 26, 2010 at 01:55 PM
Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 - Aug 14, 2010 at 02:48 PM
I've been trying to create a script to delete all files within a tree structure that were created more than 14 days ago.

var str d, n, list, file
lf -r -n "*" $d (($ftype=="f") AND ($fctime < addtime(diff("-"+$n)))) > $list
while ($list <> "")
do
lex "1" $list > $file
system del ("\""+$file+"\"")
echo -e "DEBUG: Deleted file " $file
done

I've tried the above using "C:/Scripts/delete.txt" d("X:/mypath") n("14")
but it deletes all files including those created today.

I've also tried using $today to call today's date and subtracting 14 days, to no benefit.

Goals:
Delete all files older than 14 days in a directory tree structure
Run automatically w/o having to enter a date in the format mmddyyyy as I've seen with other scripts.

1 reply

Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 14
Aug 14, 2010 at 02:48 PM
Script is called as

script "C:/Scripts/delete.txt" d("X:/mypath") n("14") 




n is number of days.

($fctime < addtime(diff("-"+$n)))


From the documentation for the function addtime(), (I am copying this section from the biterscripting website)


Leading characters may be dropped. Following examples illustrate.

"2" 2 seconds. (Please note that "2" is treated as 2 seconds, and NOT as 20 seconds.)
"321" 3 minutes, 21 seconds
"3000" 30 minutes
"30000000" 30 days
"0030000000" 30 days
"365000000" 365 days



So, the way the script is coded, it is deleting files older than 14 seconds, not 14 days. To make it 14 days, change the above condition to

($fctime < addtime(diff("-"+$n+"000000")))


The zeros are for hhMMss.
3