Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Forfiles

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge of how to use Forfiles. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

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}]]

Parameters.

/ p Path

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

/ 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 whose date 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, + is used. The valid range for DD is 0-32768.

/?

Displays help at the command prompt.

Annotation

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

The full path to the file

@ relpath

Relative path to the file

@ isdir

If the file type is a 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

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 in the tree with the * .txt extension. Alternatively, you can execute each batch file (* .bat) on the C:\ drive with the file name "Myinput.txt" as the first parameter.

By using forfiles, you can do any of the following:

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

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

Use the @ isdir variable to distinguish between files and directories.

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

Forfiles works by executing the Loop subdirectory tag on a tool designed 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 / masks. * / c "cmd / c if @ isdir==true echo @ file is a directory"

"to list all files on drive C: that have existed for more than 100 days, type:"

Forfiles / p c:\ / s / days. * / dt-100 / c "cmd / c echo @ file: date > = 100 days"

To list all files created before January 1, 1993 on drive C, and display "file is quite old!" for files with a date earlier than January 1, 1993, type:

Forfiles / p c:\ / s / masks. * / 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 / masks. * / c "cmd / c echo extension of @ file is 0x09@ext0x09" With:

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 existed for more than 100 days, type:"

Forfiles / p c:\ / s / m *. * / d tmur100 / c "cmd / c echo @ file: date > = 100 days"

To list all files created before January 1, 1993 on drive C, and display "file is quite old!" for files with a date earlier than January 1, 1993, type:

Forfiles / p c:\ / s / m *. * / d tmur01011993 / 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 / masks. * / c "cmd / c echo extension of @ file is 0x09@ext0x09"

Format legend

Format meaning

Italic

Information that the user must provide

Bold type

The user must type exactly the element shown

Ellipsis (.)

Parameters that can be repeated multiple times on the command line

Between parentheses ([])

Optional item

Between curly braces ({}); separate options with a vertical bar (|). Example: {even | odd}

The user must select an option group from which only one option can be selected

Courier font

Code or program output

These are all the contents of the article "how to use Forfiles". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report