Introduction to the use of forfiles in Windows

Source: Internet
Author: User

forfiles [/P pathname] [/M searchmask] [/S]

[/C command] [/d [+ |-] {YYYY/MM/DD | dd}]


Describe:

Select a file (or a set of files) and on that file

Executes a command. This helps with batch jobs.


Parameter list:

/P pathname Indicates the path to start the search. The default folder is the current working directory (.).

/M Searchmask search for files based on the search mask. The default search mask is ' * '.

/S Guide Forfiles recursion to subdirectories. Like "dir/s".

/C command represents the commands executed for each file. The command string should be enclosed in double quotation marks.

The default command is "cmd/c echo @file". The following variables

Can be used in the command string:

@file-Returns the file name.

@fname-Returns the file name without an extension.

@ext-returns only the file extension.

@path-Returns the full path of the file.

@relpath-Returns the relative path of the file.

@isdir-Returns "TRUE" if the file type is a directory;

If it is a file, return "FALSE".

@fsize-Returns the file size in bytes.

@fdate-Returns the date the file was last modified.

@ftime-Returns the time the file was last modified.

To include special characters at the command line, use the character 0xHH

The form uses hexadecimal code (for example, 0x09 is tab).

The internal CMD.exe command should begin with "CMD/C".

/d Date Select the file whose last modification date is greater than or equal to (+)

or less than or equal to (-) the date specified in the "YYYY/MM/DD" format;

"YYYY/MM/DD" format; or selects files with a

Current date plus "DD" day, or less than or equal to (-) current

Date minus "DD" days. A valid "DD" number of days can be

Any number in the range 0-32768. If not specified,

"+" is used as the default symbol.

/? Displays this help message.


Example:

Forfiles/?

Forfiles

forfiles/p c:\windows/s/M dns*.*

FORFILES/S/M *.txt/c "cmd/c type @file | More

forfiles/p c \/s/m *.bat

FORFILES/D -30/m *.exe

/C "cmd/c Echo @path 0x09 was changed before 30. "

FORFILES/D 2001/01/01

/C "cmd/c Echo @fname is new on January 1, 2001. "

FORFILES/D +2018/2/1/c "cmd/c Echo @fname is new today. "

forfiles/m *.exe/d +1

FORFILES/S/M *.doc/c "cmd/c echo @fsize"

forfiles/m *.txt/c "cmd/c if @isdir ==false notepad.exe @file"


Introduction to the use of forfiles in Windows

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.