The forfiles command has several command-line switches. If no switches or parameters given, it outputs the name of every file in the current directory.
This option treats glob patterns *.* and * differently. The former will only match files with a dot in their name, while the latter will match even those with no dot or extension. Most DOS/Windows commands will match files with no extension even when given a *.* pattern.
The command string is executed as given, except as noted below.
Sequences of the form 0xFF, where "0x" is literal, and "FF" represents any two-digit hexadecimal number, are replaced with the corresponding single-byte value. This can be used to embed non-printing ASCII characters, or extended ASCII characters.
The sequence \" is replaced with a literal quotation mark ". Using the 0x sequence form described previously, 0x22 can also be used, which additionally hides the " from the command interpreter.
Several variables are provided, to be used in the command as placeholders for the values from each file. Variables are technically not required, but must be used if the command is to vary for each file.
The date switch (/D) selects files based on their last modified date, given a date argument.
The date argument can be given as a literal date, in MM/DD/YYYY format (other date formats are not accepted). Alternatively, the date argument can be given as a number, in which case it is taken to mean an age in days (i.e., the day date days before the present date).
If the date argument begins with a minus (-), only files modified on or before the given date are selected (older file / modified earlier). Otherwise, only files modified on or after the given date are selected (younger files / modified later). An explicit plus (+) may be given, but is the default. Note that both modes select files on the given date. There is no way to select files only on a given date (without also either before or after).
The following command selects all log files (*.LOG) in the Windows directory 30 days or older, and lists them with their date.
The following command would delete the same files.
The use of CMD /C is required in the above examples, as both ECHO and DEL are internal to the command processor, rather than external utility programs.
"Forfiles.exe - Windows 98 Resource Kit Utility". Archived from the original on 2020-01-11. Retrieved 2020-01-11. https://web.archive.org/web/20200111203651/https://www.activexperts.com/admin/reskit/reskit98/forfiles/ ↩
Forfiles.exe - Windows 2000 Resource Kit Utility https://www.activexperts.com/admin/reskit/reskit2000/forfiles/ ↩