DOS loop: detailed examples of for commands (batch compression into custom extension files)

Source: Internet
Author: User

For parameter % variable name in (related file or command) Do Command executed

Parameters: For has four parameters/D/L/R/f. Their functions are explained in the following example:
% Variable name: this variable name can be a single lowercase A-Z or an uppercase A-Z, they are case sensitive ~, For will give each read value to him!
In: Command Format. Just write it!
(Related file or command): For reads something and assigns it to the variable. If you do not understand it, refer to the following example.
Do: Command Format. Just write it!
The command to be executed: This is where you want to perform any operation on the value of each variable.
You can enter for/in cmd /? See the help provided by the system! I will also give it here for your reference.
For % variable in (SET) do command [command-parameters]
% Variable specifies a single letter replaceable parameter.
(SET) specifies one or more files. Wildcard characters can be used.
Command specifies the Command executed on each file.
Command-Parameters
Specify parameters or command line switches for specific commands.

Now let's start with the meaning of each parameter.

1. Parameter/d

If the set contains wildcards, it is specified to match the directory name instead of the file name.

2. Parameter/R

Currently, all file names in the specified path are read. Note that the file name

@ Echo off
For/R c: \ % I in (*. EXE) Do echo % I
Pause
Let's save the bat to drive D and execute it at will. I will see that he put the C root directory, and all the EXE files under each subdirectory are listed !!!!

3. Parameter/L

This set indicates a sequence of numbers from start to end in incremental form.

(, 5) will generate the sequence 1 2 3 4 5, (5,-) will generate the sequence (5 4 3 2 1 ).

@ Echo off
For/L % I in (1, 1, 5) do start cmd
Pause

Supports dos cyclic batch processing to intelligently process files. Batch compress to custom extension files

@ Echo off
For/R "e: \ test" % d in (*. DB) do zip % ~ Nd. Custom suffix % ~ Nd. DB
Pause

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.