FORFILES /D 08/18/2011 /C "cmd /c echo @fname is new Today"
MM-DD-YYYY
FORFILES /D 08/18/2011 /C "cmd /c echo @fname is new Today"
FORFILES.exe (Resource Kit)
Select a file (or set of files) and execute a command on each file. Batch processing.
Syntax
FORFILES [/p Path] [/m Mask] [/s] [/c Command] [/d [+ | -] {dd/MM/yyyy | dd}]
Key
/p Path The Path to search (default=current folder)
/s Recurse into sub-folders
/C command The command to execute for each file.
Wrap the command string in double quotes.
Default = "cmd /c echo @file"
The Command variables listed below can also be used in the
command string.
/D date Select files with a last modified date greater than or
equal to (+), or less than or equal to (-),
the specified date using the "dd/MM/yyyy" format;
or selects files with a last modified date greater than
or equal to (+) the current date plus "dd" days, or
less than or equal to (-) the current date minus "dd" days.
A valid "dd" number of days can be any number in
the range of 0 - 32768.
"+" is taken as default sign if not specified.
Command Variables:
@file The name of the file.
@fname The file name without extension.
@ext Only the extension of the file.
@path Full path of the file.
@relpath Relative path of the file.
@isdir Returns "TRUE" if a file type is a directory,
and "FALSE" for files.
@fsize Size of the file in bytes.
@fdate Last modified date of the file.
@ftime Last modified time of the file.
Internal CMD.exe commands must be preceded with "cmd /c".
If ForFiles finds one or more matches if will return %errorlevel% =0
If ForFiles finds no matches if will return %errorlevel% =1 and will print "ERROR: No files found with the specified search criteria."
Examples:
Print a warning if the testfile is 5 days old or older:
C:\> forfiles /m testfile.txt /c "cmd /c echo file is too old" /d -5
Delete the testfile if it is is 5 days old or older:
C:\> forfiles /m testfile.txt /c "cmd /c Del testfile.txt " /d -5
Find .xls file that were last modified 30 days ago or longer
C:\> FORFILES /M *.xls /C "cmd /c echo @path was changed 30 days ago" /D -30
List the size of all .doc files:
C:\> FORFILES /S /M *.doc /C "cmd /c echo @fsize"
An alternative method of dealing with files older or newer than a specified date is to use ROBOCOPY
MM-DD-YYYY
FORFILES /D 08/18/2011 /C "cmd /c echo @fname is new Today"
FORFILES.exe (Resource Kit)
Select a file (or set of files) and execute a command on each file. Batch processing.
Syntax
FORFILES [/p Path] [/m Mask] [/s] [/c Command] [/d [+ | -] {dd/MM/yyyy | dd}]
Key
/p Path The Path to search (default=current folder)
/s Recurse into sub-folders
/C command The command to execute for each file.
Wrap the command string in double quotes.
Default = "cmd /c echo @file"
The Command variables listed below can also be used in the
command string.
/D date Select files with a last modified date greater than or
equal to (+), or less than or equal to (-),
the specified date using the "dd/MM/yyyy" format;
or selects files with a last modified date greater than
or equal to (+) the current date plus "dd" days, or
less than or equal to (-) the current date minus "dd" days.
A valid "dd" number of days can be any number in
the range of 0 - 32768.
"+" is taken as default sign if not specified.
Command Variables:
@file The name of the file.
@fname The file name without extension.
@ext Only the extension of the file.
@path Full path of the file.
@relpath Relative path of the file.
@isdir Returns "TRUE" if a file type is a directory,
and "FALSE" for files.
@fsize Size of the file in bytes.
@fdate Last modified date of the file.
@ftime Last modified time of the file.
Internal CMD.exe commands must be preceded with "cmd /c".
If ForFiles finds one or more matches if will return %errorlevel% =0
If ForFiles finds no matches if will return %errorlevel% =1 and will print "ERROR: No files found with the specified search criteria."
Examples:
Print a warning if the testfile is 5 days old or older:
C:\> forfiles /m testfile.txt /c "cmd /c echo file is too old" /d -5
Delete the testfile if it is is 5 days old or older:
C:\> forfiles /m testfile.txt /c "cmd /c Del testfile.txt " /d -5
Find .xls file that were last modified 30 days ago or longer
C:\> FORFILES /M *.xls /C "cmd /c echo @path was changed 30 days ago" /D -30
List the size of all .doc files:
C:\> FORFILES /S /M *.doc /C "cmd /c echo @fsize"
An alternative method of dealing with files older or newer than a specified date is to use ROBOCOPY
No comments:
Post a Comment