How can I have multiple date filters in a forfiles command?

125 Views Asked by At

I'm trying to catch all the files in a folder taking in account two filters, the first one is the creation date have to be greater than 01/01/2020 and the creation date have to be lower that today-6.

I don't know how to apply two filters in the same forfiles command line. This is what I have:

forfiles /P c:\temp /D +01/01/2020 /C "cmd /c echo @path"
1

There are 1 best solutions below

0
aschipfl On

Well, forfiles doesn't filter for the creation date, rather does it regard the last modification date (though not the time), and it supports only a single such filter.

However, you may nest two commands:

forfiles /P "C:\TEMP" /D +01/01/2020 /C "forfiles forfiles /P @path\.. /M @file /D -6 /C 0x22cmd /D /C if @isdir==FALSE echo 00x7840path0x22" 2> nul

Note, that the expected date format behind /D depends on the actual locale settings.

Also refer to this post: FORFILES date -after- (date calc in cmd file)