VERSCHUEREN Geert said:
is there a way to delete the files older than 3 days in a specific path by
just using msdos(/CLI) batch scripting and without using forfiles.exe from
Using 'pure' batch, yes, there's a couple of ways. I'll briefly describe the less
inefficient method.
First determine and load the current date components into variables, then
convert the date into the number of elapsed days since date x. Then subtract
the required number of days (three in your case) and convert the result back
into a date. Combine the resulting date components into one variable in the
format of yyyymmdd or yyyymmddhhmm (depends on the resolution you require,
for hhmm, you might use 0000).
See this query for examples on obtaining the current date:-
http://groups.google.com/groups?q=batch.nt OR%
20cmdprompt.admin+ritchie+getdate+gettime
See this query for examples of converting a date to a number and vice-versa:-
http://groups.google.com/groups?q=batch.nt OR cmdprompt.admin+ritchie+datetodays+daystodate
Next use a FOR /F loop to parse the output from the DIR command which is used
to enumerate the directory of interest. Each 'record' is then parsed again by
a second (inner) FOR /F loop to extract the file's timestamp components. This
loop then CALLs a routine passing the date/time info and filename.
The called routine can now perform a _string_ comparison using the IF
command in conjuction with the extended comparison operators (GTR, GEQ etc)
and if true, perform the required operation on the file (i.e. delete the file).
If the final script is to run on a single machine, it's really quite
straightforward. If it will be used on two or more machine it gets slightly
more complex, requiring one of two extra FOR /F to 'fix' the date and take
into account different O/S - but perfectly do-able.
Post again for further info.