Forfiles Command Detailed

Source: Internet
Author: User
Forfiles

Select the file you want to batch from the folder or tree. Grammar

forfiles [/P Path] [/M searchmask] [/s] [/C Command] [/d[{+ |-}] [{mm/dd/yyyy | DD}]] Argument

/P Path

Specify Path, indicating where to start the search. The default folder is the current working directory, which is specified by typing a period (.).

/M Searchmask

Search for files by Searchmask. The default searchmask is *.*.

/s

Instructs Forfiles to search in subdirectories.

/C Command

Runs the specified Command on each file. command strings with spaces must be enclosed in quotation marks. The default Command is "cmd/c echo @file".

/d[{+ |-}] [{mm/dd/yyyy | DD}]

Select a file with a date that is greater than or equal to (+) (or less than or equal to (-)) The specified date, where mm/dd/yyyy is the specified date and DD is the current date minus DD days. If + or-is not specified, the + is used. The valid range for DD is 0-32768.

/?

Displays help at the command prompt. Comments

Forfiles is most commonly used in batch files.

The forfiles/s is similar to dir/s.

The following table lists the variables that can be used in the  /cCommand  command string.

variable description

@file

File name

@fname

File name with no extension

@ext

File name extension

@path

Full path of file

@relpath

Relative path of file

@isdir

If the file type is a directory, the value evaluates to TRUE, otherwise the value is FALSE

@fsize

File size in bytes

@fdate

File last Modified date stamp

@ftime

File Last modified timestamp

With Forfiles, you can run commands on multiple files or pass parameters to multiple files. For example, you can run the TYPE command on all files with *.txt extensions in the tree. Alternatively, you can use the filename "Myinput.txt" as the first argument, in the c:/ Execute each batch file (*.bat) on the drive.

By using Forfiles, you can perform any of the following actions:

Use/d to select files by absolute or relative date.

Build an archive tree of files using variables such as @fsize (file size) and @fdate (file date).

Use @isdir variables to differentiate between files and directories.

Format the output by including special characters on the command line and by using the hexadecimal code 0xHH wrapping character.

Forfiles works by executing the "loop subdirectory" tag on a tool designed to work with only a single file.

Example

To list all the batch files on drive C:, type:

forfiles/p c://s/m*.bat/c "cmd/c Echo @file is a batch file"

To list all the directories on drive C:, type:

forfiles/p c://s/m*.*/C "cmd/c if @isdir ==true echo @file is a directory"

To list all files that have more than 100 days on the drive C:, type:

forfiles/p c://s/m*.*/dt-100/c "cmd/c echo @file:d ate >= days"

To list all the files that were created prior to January 1, 1993 on drive C: and for files that have a date earlier than January 1, 1993 to display the file is quite old!, type:

forfiles/p c://s/m*.*/dt-01011993/c "cmd/c Echo @file is quite old!"

To list the extensions for all files on drive C: In column format, type:

forfiles/p c://s/m*.*/C "cmd/c echo extension of @file is 0x09@ext0x09" with:

To list all the batch files on drive C:, type:

forfiles/p c://s/m *.bat/c "cmd/c Echo @file is a batch file"

To list all the directories on drive C:, type:

forfiles/p c://s/m *.*/C "cmd/c if @isdir ==true echo @file is a directory"

To list all files that have more than 100 days on the drive C:, type:

forfiles/p c://s/m *.*/d t-100/c "cmd/c echo @file:d ate >= days"

To list all the files that were created prior to January 1, 1993 on drive C: and for files that have a date earlier than January 1, 1993 to display the file is quite old!, type:

forfiles/p c://s/m *.*/d t-01011993/c "cmd/c Echo @file is quite old!"

To list the extensions for all files on drive C: In column format, type:

forfiles/p c://s/m*.*/C "cmd/c echo extension of @file is 0x09@ext0x09"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.