Home > Commands A-M > Batch F

FORFILES


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Batch process multiple files.


Syntax

FORFILES [-pPath] [-s] [-dDate] [-mMask] [-v] [-cCommand]


Parameters

none.


Switches
-cCommand (NT4)
Command to execute on each file, default="CMD /C Echo @FILE"
The variables can be used in the -cCommand (must be upper case): To ECHO Hex characters in the Command use: 0xHH
-dDate (NT4)
Date can be:
-mMask (NT4)
Search mask (wildcards allowed), default=*.*
-pPath (NT4)
Path to search, default=current folder
-s (NT4)
Recurse into sub-folders.
-v (NT4)
Verbose report.

Related

FOR - Conditionally perform a command several times.
MUNGE - Find and Replace text within file(s).
Equivalent Linux BASH commands:
for - Expand words, and execute commands.
case - Conditionally perform a command.
eval - Evaluate several COMMANDS/arguments.
if - Conditionally perform a command.
gawk - Find and Replace text within file(s).
m4 - Macro processor.
until - Execute commands (until error).
while - Execute commands.


Notes
Version 1.0

Version 1.0 of FORFILES will only search for files newer than a specified date -dDate).


Version 1.1

Version 1.1 of FORFILES will search for files Newer or Older than a specified date -dDate).

Version 1.1 can be downloaded from ftp://www.microsoft.com/


Examples

To find every text file on the C: drive:

    FORFILES -pC:\ -s -m*.TXT -c"CMD /C Echo @FILE is a text file"

To show the path of every HTML file on the C: drive:

    FORFILES -pC:\ -s -m*.HTML -c"CMD /C Echo @RELPATH is the location of @FILE"

List every folder on the C: drive:

    FORFILES -pC:\ -s -m*. -c"CMD /C if @ISDIR==TRUE echo @FILE is a folder"

For every file on the C: drive list the file extension in double quotes:

    FORFILES -pC:\ -s -m*.* -c"CMD /c echo extension of @FILE is 0x22@EXT0x22

List every file on the C: drive last modified over 100 days ago:

    FORFILES -pC:\ -s -m*.* -d-100 -c"CMD /C Echo @FILE : date >= 100 days"

Find files last modified before 01-Jan-1995:

    FORFILES -pC:\ -s -m*.* -d-010195 -c"CMD /C Echo @FILE is quite old!"

Errorlevels

none.


Availability
External Resource Kit
DOS
none
Windows
none
Windows NT
NT4 NT2003