Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: MS DOS .: How to Batch process multiple files using FORFILES.exe Tool (Resource Kit + update)

How to Batch process multiple files using FORFILES.exe Tool (Resource Kit + update)

Batch process multiple files

Syntax NT/2000:
      FORFILES [-pPath] [-s] [-dDate] [-mMask] [-cCommand] 

Syntax 2003/Vista:
      FORFILES [-p Path] [-s] [-d Date] [-m Mask] [-c Command] 

key
   Path   : Path to search  (default=current folder)

   -s     : Recurse into sub-folders

   Date   : This can be
              +DDMMYY to select files newer than a given date
                      (filedate >=DDMMYY) or
              -DDMMYY to select files older than a given date
                      (filedate <=DDMMYY) or
              (Recent versions format the date mask as: +MM/DD/YY 

              +DD to select files newer than DD days ago or
              -DD to select files older than DD days ago

   Mask   : Search mask (wildcards allowed)  default=*.*

Command : Command to execute on each file. default="CMD /C Echo @FILE"

The following variables can be used in -cCommand (must be upper case)

@FILE,
@FNAME_WITHOUT_EXT,
@EXT,
@PATH,
@RELPATH,

@ISDIR,
@FSIZE,
@FDATE,
@FTIME

To ECHO Hex characters in the Command use: 0xHH

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!" note: '0x22' is hex 22 - the double quote character - put these around any long filenames.

Version 1.0 of FORFILES will only search for files newer than a specified date.
Version 1.1 (described above) can search for file dates Newer or Older then a specified date.
The Vista/2003 version of ForFiles is not compatible with Windows 2000

An alternative method of dealing with files older or newer than a specified date is to use ROBOCOPY


How helpful was this article to you?

Related Articles

article How to Automated cleanup of Temp files, Internet files, downloaded files, recycle bin using CLEANMGR.EXE Tool(XP)
Syntax CLEANMGR option Options ...

(No rating)  3-7-2008    Views: 412   
article How to remove a running process from memory using KILL command (Resource kit)
Remove a running process from memory. ...

(No rating)  3-9-2008    Views: 129   
article How to Accept user input to a batch file using CHOICE.EXE (Resource KIT)
Accept user input to a batch file.Choice...

(No rating)  3-7-2008    Views: 208   

User Comments

Add Comment
No comments have been posted.