The following command line lists every .JS file in the current directory and all subfolders, not just the files last modified in the previous 10 days as expected by me.
FORFILES /S /D -10 /M *.js /C "cmd /c echo @path"
Whereas this command lists only the .JS files modified on or after 2/20/2022.
FORFILES /S /D 2/20/2022 /M *.js /C "cmd /c echo @path"
Any ideas why using the option /D -10 doesn't result in the expected output?
The execution of
forfiles /?in a command prompt window to show the usage help results on Windows with language English US, but with region/country/format German (Austria) configured for the user account, for option/Din the output:The date format is region dependent.
dd.MM.yyyymeans:01to31.01to12.2022.The specification of a date in international date format
yyyy-MM-ddresults on my PC in the error message:Some examples for a better understanding:
This outputs all file system entries (file and directory names) with last modification date newer (greater than) or equal August 13th, 2021.
This outputs all file system entries (file and directory names) with last modification date older (less than) or equal August 13th, 2021.
This outputs all file system entries (file and directory names) with last modification date older (less than) or equal February 16th, 2022 on current date being February 26th, 2022 (
26.02.2022).This outputs all file system entries (file and directory names) with last modification date newer (greater than) or equal March 08th, 2022 on current date being February 26th, 2022 (
26.02.2022). Such a date specification does not make much sense in most cases if the current date is correct and so files/folders with a future date do most likely not exist at all. So such a date specification results usually in the error message:Some more hints:
The file/folder names are always output enclosed in
"which is important to know on using for example in a batch file:The file/folder names are never output with path even on using option
/S.So capturing the output of forfiles using
for /Ffor further processing the files/folders more efficient withcmd.exeinstead of using the FORFILES option/Cmakes no sense on using option/Sto search also in subdirectories of the current directory respectively the directory specified with FORFILES option/P.The usage of FORFILES without option
/Dmakes never sense as in this case it is always more efficient and definitely better to use the internal command for of the Windows Command Processor cmd.forfiles.exedoes by default not exist on Windows XP and older Windows client versions.forfiles.exein Windows system32 directory of Windows Server 2003 can be copied to the Windows system32 directory of a PC with Windows XP. Windows Server 2003 uses the same kernel as Windows XP.By the way:
choice.exeandrobocopy.exein Windows system32 directory of Windows Server 2003 can be also copied to Windows system32 directory of Windows XP as not existing by default on Windows XP too.PS: A directory is for file systems like NTFS, FAT12, FAT16, FAT32, exFAT a file with the attribute
d.