Top Qs
Timeline
Chat
Perspective

Forfiles

From Wikipedia, the free encyclopedia

Remove ads

forfiles is a computer software utility for Microsoft Windows, which selects files and runs a command on them. File selection criteria include name and last modified date. The command specifier supports some special syntax options. It can be used directly on the command line, or in batch files or other scripts.

Remove ads

The forfiles command was originally provided as an add-on, in the Windows 98,[1] Windows NT[citation needed] and Windows 2000[2] Resource Kits. It became a standard utility with Windows Vista, as part of the new management features.

Remove ads

Usage

Summarize
Perspective

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.

Switches

More information Switch, Argument ...

Command syntax

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.

More information Variable, Meaning ...

Date syntax

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).

Remove ads

Examples

The following command selects all log files (*.LOG) in the Windows directory 30 days or older, and lists them with their date.

C:\>FORFILES /P C:\Windows /M *.LOG /D -30 /C "CMD /C ECHO @FDATE @FILE"
6/12/2015 "iis7.log"
5/28/2015 "msxml4-KB954430-enu.LOG"
5/28/2015 "msxml4-KB973688-enu.LOG"
5/26/2015 "setuperr.log"

The following command would delete the same files.

C:\>FORFILES /P C:\Windows /M *.LOG /D -30 /C "CMD /C DEL @PATH"

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.

Remove ads

See also

  • cmd.exe – The program implementing the Windows command-line interpreter
  • Foreach loop – The FOR and FORFILES commands both implement a for-each loop
  • find (Unix) – Unix command that finds files by attribute, similar to forfiles
  • find (Windows) – DOS and Windows command that finds text matching a pattern
  • grep – Unix command that finds text matching a pattern, similar to Windows find

Further reading

  • "FORFILES", Microsoft Windows (Computer software), 6.1.7600.16385, Microsoft, 13 July 2009.
  • "Forfiles". TechNet. Microsoft. April 17, 2012. Retrieved 28 April 2016.
  • Simon Sheppard. "FORFILES.exe". SS64. Retrieved 28 April 2016.

References

Loading content...
Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads