Fri Sep 14, 2018 4:41 pm
I use this script to find the old 1-day files.
only that the result gives me all the files in the rb, is it possible to search in just one specific folder example disk1/log?
This is the script
thank you
##############################################################################
{
# how many days ago
:local daysAgo 1;
# only show files that contain this in their name txt
:local filter "txt";
# months array
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
# get current date
:local curDate [ /system clock get date ];
# extract current month
:local curMonth [ :pick $curDate 0 3 ];
# get position of our month in the array = month number
:set curMonth ([ :find $months $curMonth -1 ] + 1);
# extract current day
:local curDay [ :pick $curDate 4 6 ];
# extract current year
:local curYear [ :pick $curDate 7 11 ];
# loop through all files
:foreach i in=[/file find] do={
# get this file's creation time
:local fileDate [/file get number="$i" creation-time]
# extract the date
:set fileDate [ :pick $fileDate 0 11 ];
# extract the month
:local fileMonth [ :pick $fileDate 0 3 ];
# get position of our month in the array = month number
:set fileMonth ([ :find $months $fileMonth -1 ] + 1);
# extract the day
:local fileDay [ :pick $fileDate 4 6 ];
# extract the year
:local fileYear [ :pick $fileDate 7 11 ];
# the sum of total days
:local sum 0;
# subtract the file's year from the current year, multiply times 365 to get approx days, add to sum
:set sum ($sum + (($curYear - $fileYear)*365));
# subtract the file's month from the current month, multiply times 30 to get approx days, add to sum
:set sum ($sum + (($curMonth - $fileMonth) * 30));
# subtract the file's day from the current day, add to sum
:set sum ($sum + ($curDay - $fileDay));
# if the sum is greater than or equal to our daysAgo and the file name contains our filter
:if ($sum >= $daysAgo && [/file get number="$i" name]~"$filter") do={
# show file info to the terminal $sum =giorni passati
:put ([/file get number="$i" creation-time ] . "\t" . [/file get number="$i" name] . " - " . "$sum days ago");
# if a match was found cancello i files vecchi
:put ( . "\t" .[/file get number="$i" name] );
#/file remove ( . "\t" .[/file get number="$i" name] );
}
}
}
#################################################################################