Forfiles official Microsoft Introduction

Source: Internet
Author: User

Forfiles
Select the file to be processed in batches from the folder or tree.

Syntax
Forfiles [/p Path] [/m SearchMask] [/s] [/c Command] [/d [{+ |-}] [{MM/DD/YYYY | DD}]

Parameters
/P Path
Specify Path to indicate where to start searching. The default folder is the current working directory, which is specified by entering a period.
/M SearchMask
Search for files by SearchMask. The default SearchMask is *.*.
/S
Indicates that forfiles is searched in the subdirectory.
/C Command
Run 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 whose date is greater than or equal to (+) (or less than or equal to (-) the specified date. MM/DD/YYYY is the specified date, DD is the current date minus DD Day. If + or-is not specified, + is used. The effective range of DD is 0-32768.
/?
Display help at a command prompt.
Note
Forfiles is most commonly used in batch files.

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 without extension

@ Ext

File Extension

@ Path

Complete file path

@ Relpath

File relative path

@ Isdir

If the file type is directory, the calculated value is TRUE; otherwise, the value is FALSE.

@ Fsize

File Size in bytes

@ Fdate

The Last modified Date stamp in the file

@ Ftime

The last modified timestamp in the file.

Using 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 the *. txt extension in the tree. You can use the file name extension myinput.txt as the first parameter to execute each batch of files (*. bat) on the C: \ drive ).

By using forfiles, you can perform any of the following operations:

Use/d to select a file based on the absolute or relative date.

Use variables such as @ fsize (file size) and @ fdate (File date) to construct the File Archive tree.

Use the @ isdir variable to differentiate files and directories.

You can format the output content by including special characters in the command line and using the hexadecimal code 0xHH.

Forfiles works by executing the "loop subdirectory" mark on a tool that is intended to process only a single file.

Example
To list all batch files on drive C:, type:
Forfiles/p c: \/s/m *. bat/c "cmd/c echo @ file is a batch file"
To list all 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 on drive C that have been present for more than 100 days, type:
Forfiles/p c: \/s/m *. */dt-100/c "cmd/c echo @ file: date> = 100 days"
To list drive C: All files created before July 15, January 1, 1993, and "file is quite old!" is displayed for files earlier than July 15, January 1, 1993 !", Enter:
Forfiles/p c: \/s/m *. */dt-01011993/c "cmd/c echo @ file is quite old! "
To list the extensions of all files on drive C: In column format, type:
Forfiles/p c: \/s/m *. */c "cmd/c echo extension of @ file is 0x09 @ ext0x09":
To list all batch files on drive C:, type:
Forfiles/p c: \/s/m *. bat/c "cmd/c echo @ file is a batch file"
To list all 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 on drive C that have been present for more than 100 days, type:
Forfiles/p c: \/s/m *. */d t-100/c "cmd/c echo @ file: date> = 100 days"
To list drive C: All files created before July 15, January 1, 1993, and "file is quite old!" is displayed for files earlier than July 15, January 1, 1993 !", Enter:
Forfiles/p c: \/s/m *. */d t-01011993/c "cmd/c echo @ file is quite old! "
To list the extensions of all files on drive C: In column format, type:
Forfiles/p c: \/s/m *. */c "cmd/c echo extension of @ file is 0x09 @ ext0x09"

Format legend

Format Meaning

Italics

REQUIRED INFORMATION

Bold

You must accurately enter the elements shown in

Ellipsis (...)

Parameters that can be repeated multiple times in the command line

Between brackets ([])

Optional items

The options are separated by vertical bars (|) between braces. Example: {even | odd}

The user must select only one option of the quota group.

Courier font

Code or program output

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.