SYNTAX:
FORFILES [/P pathname] [/M searchmask] [/S] [/C command] [/D [+ | -] {dd-MM-yyyy | dd}]
Help Command: FORFILES /?
/P pathname
/M searchmask
/S to list sub-directories
/C Command
/? Displays this help message.
To delete the files older than 10 days,
forfiles -p "E:" -s -m *arch* -d -10 -c "cmd /c del @file"
To print the list of files:
FORFILES [/P pathname] [/M searchmask] [/S] [/C command] [/D [+ | -] {dd-MM-yyyy | dd}]
Help Command: FORFILES /?
/P pathname
/M searchmask
/S to list sub-directories
/C Command
The default command is "cmd /c echo @file".
The following variables can be used in the
command string:
@file - returns the name of the file.
@fname - returns the file name without
extension.
@ext - returns only the extension of the
file.
@path - returns the full path of the file.
@relpath - returns the relative path of the
file.
@isdir - returns "TRUE" if a file type is
a directory, and "FALSE" for files.
@fsize - returns the size of the file in
bytes.
@fdate - returns the last modified date of the
file.
@ftime - returns the last modified time of the
file.
/D date /? Displays this help message.
Example:
To delete the files older than 10 days,
forfiles -p "E:" -s -m *arch* -d -10 -c "cmd /c del @file"
To print the list of files:
To find every text file on the C: drive
FORFILES -p "C:\ /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 -p "C:\ -S -M*.HTML /C"CMD /C Echo @RELPATH is the location of @FILE"
List every folder on the C: drive
FORFILES -p "C:\ /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 -p "C:\ /S /M*.* /C"CMD /C echo extension of @FILE is 0x22@EXT0x22"
List every file on the C: drive last modified over 365 days ago
FORFILES -p "C:\ /S /M*.* -d-365 /C"CMD /C Echo @FILE : date >= 100 days"
Find files last modified before 01-Mar-2018
FORFILES -p "C:\ /S /M*.* -d-010318 -C"CMD /C Echo @FILE is quite old!"