Delete files that are older than 5 days
The following command recursively (/s
) deletes files below p:\ath\to\directory
that are older than 5 days.
The
if @isdir == FALSE
makes sure that
del
is only applied to files but not to directories.
The variable @path
is expanded to the absolute path of the matching files. (@file
would expand to the file name only).
C:\> forfiles /s /p p:\ath\to\directory /d -5 /c "cmd /c if @isdir == FALSE del @path"
Print files with a modification that is younger than a given date
The following command prints files whose modification date is after 12/01/2019
. @fdate
and @ftime
expand to the printed file's modification date and time.
P:\ath\to\directory> forfiles /s /m *.txt /d +12/01/2019 /c "cmd /c if @isdir == FALSE echo @path [@fdate @ftime]"
In order to reverse the criteria, /d -12/01/2019
should be used.