Batch processing Getting Started manual for batches Common DOS command posts (MD, RD, Ren, move) _dos/bat

Source: Internet
Author: User
Tags manual require

1.3 Learning MD Rd ren move command

Learning points:
1. Create folder: MD
2. Delete folder: Rd
3. Renaming files (clips): ren
4. Moving files (folders): Move

I. Creating a folder: MD

The MD command is used to create a folder, and the path in the following example can be default, if the default is to create a new folder in the current directory, and if you create a new folder with spaces or special symbols on it, enclose it in double quotes.

1. Create a single folder
Format: MD [path \] Directory

Example 1
MD D:\ABC
Set up a folder named ABC under D disk.

Example 2
MD ABC
This is the default path, and a folder named ABC is created under the current directory.

Example 3
MD "D:\My Game"
Under D disk, create a folder named My game.
For a new folder name that contains spaces or special symbols, be sure to enclose the folder name in double quotes "".

Example 4
MD "C:\Documents and settings\456^ 789"
Create a folder named 456^ 789 under C:\Documents and settings, because there are spaces in the path, so we enclose the path and folder name in double quotes "".

2. Create multiple catalogs at the same time
Format: MD [path \] Directory 1 [path \] Directory 2 [path \] Directory 3 ...

Example 5
MD ABC D:\gmae\123 ABCD
Create ABC and ABCD two files in the current directory, and create a folder 123 under D:\gmae.


3. Create a Multilevel Catalog
Format: MD [path \] Directory 1\ directory 2\ directory 3\ ...

If we were to set up the folder ABC under D disk, and then create a new folder in ABC, ABCD, and then build the folder in ABCD ABCDE, is there a single command that can be done at once? The answer is YES!

Example 6
MD D:\ABC\ABCD\ABCDE
That's the one order, all right? Of course you can test Luo, hehe ~


Thinking:

In Example 4 what happens if the command is not enclosed in double quotes, that is, MD C:\Documents and settings\456^ 789? This let everyone start to test, haha!!

Two. Delete folder: Rd

Deletes a directory.
RMDIR [/S] [/q] [Drive:]path
RD [/S] [/q] [Drive:]path

/S In addition to the directory itself, will also delete all subdirectories in the specified directory and
File. Used to delete a directory tree.
/q Quiet mode, with/S delete directory tree does not require confirmation


The RD command can only delete empty folders without any arguments.

Example 1.
Rd d:\123
RD ABC
The first is to delete the empty folder under D disk 123. The second is to delete the empty folder ABC under the current directory.


/S also deletes all subdirectories and files in the specified directory, in addition to the directory itself. Used to delete a directory tree.

Example 2.
RD/S d:\123
If the folder 123 is not empty, the folder 123 can be deleted by using the/s parameter.


/q Quiet mode, with/S delete directory tree does not require confirmation.

Example 3.
RD/S/q d:\123
When using the/s parameter, the system prompts: D:\123 confirm (y/n)? The/q parameter can then be used to delete it directly without asking.

Three. renaming files (clips): ren

Renames the file.
RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.

The filename1 path can be omitted and is the current directory by default. Filename2 can only be a filename and cannot use any path.


1. Renaming a single file

Example 1
ren d:\123.txt 456.bat
Rename the 123.txt to 456 and change the suffix name to bat.

Example 2
ren 123.txt 456.bat
In the default path, rename the 123.txt in the current directory to 456.bat.


2. Batch Renaming

Batch renaming by * and? These two wildcard characters. * represents any number of characters,? represents a character.

Example 3
ren *.bat *.txt
Change the file with the suffix named bat to the txt suffix file in batches.


★ For the wildcard character? More complex, this will not say, please find more relevant information!
★ When the file has hidden attributes or system properties, Ren can not be directly renamed, you need to hide the file or system attributes to remove the name can be renamed, this point we should pay attention!

Four. moving files (folders): Move

Move files and rename files and directories.

To move at least one file:
Move [/y |/-y] [drive:][path]filename1[,...] Destination

To rename a directory:
Move [/y |/-y] [drive:][path]dirname1 dirname2

[Drive:] [PATH]FILENAME1 Specifies the location and name of the file you want to move.]
destination Specifies the new location of the file. The target can contain a drive letter
And a colon, a directory name, or a combination. If you move only one file
and rename it when you move it, you can also include the file name.
[Drive:] [path]dirname1 Specifies the directory to rename.
Dirname2 the new name of the specified directory.

/y Cancels the prompt to overwrite an existing destination file.
/-y prompts to confirm overwriting an existing destination file.


1. Move the file (clip)
Basic format: move [/y |/-y] [drive:][path]filename1[,...] Destination

[Drive:] [Path]filename1[,...]
The file (folder) you want to move can use a relative path, or you can use an absolute path, and the default path defaults to the current directory.

Destination can only be a directory path, use a relative path, or use an absolute path, where the default path defaults to the current directory.

Example 1
Move D:\abc D:\ABCD
If you move the folder ABC to the folder ABCD.

Example 2
Move 123.txt ABC
Move the 123.txt in the current directory to the current folder ABC. The relative path is used here, and the default path defaults to the current directory.

Example 3
Move 123.txt E:\ABC
Move the 123.txt under the current directory to the E:\ABC directory.


2. Renaming files (folders)

Example 4
Move D:\abc D:\ABCD
Note here that if the target folder ABCD does not exist, then move ABC to D:\ and change its name to ABCD.
With this feature, the move command has the ability to rename.

Example 5
Move D:\123.txt D:\abc\456.txt
If 456.txt exists, the system will prompt you: rewrite D:\456.txt? (Yes/no/all):
123.txt will overwrite 456.txt when you enter Y. If 456.txt does not exist, move 123.txt to the D:\ABC directory and rename to 456.txt.

Example 6
move/y 123.txt 456.txt
If both 123.txt and 456.txt are present, the system will not prompt you after passing the/y parameter, and the 123.txt is covered 456.txt directly.

Example 7
Move 123.txt E:\abc\456.txt
For a spanned move, if the 456.txt presence prompts: The file exists. command does not execute, if 456.txt does not exist, move 123.txt to the E:\ABC directory and rename to 456.txt.


The ★move command can move files across partitions, but you cannot move folders across partitions.
★ When moving files across partitions, if the target location exists with the same name as the file that will be moved, the system prompts: "File exists" and the command will not execute.
★ For files that are hidden or system attributes, the move command executes only after removing their properties.


Let's conclude by:

For a pattern like move A b

1, if a, B is the same folder name,
① if b exists, move A to the B directory. (example 1);
② if B does not exist, move a to the directory where B is located, and rename to B. (Example 4).

2, if A is the filename, B is the folder name,
① will move a to the B directory. (Example 2, example 3);
② if the B folder has the same name as a file:
I A and B are the same partition, then hint: Is it covered/not covered/all covered?
II A and B are different partitions, then hint: the file exists. Do no action!

3, if a, B is the same file name,
①a and B are the same partition, and if B exists, you will be prompted whether to rename A to B, and if B does not exist, move a to the directory where B resides, and rename to B. (example 5);
②a and B are different partitions, if B exists, the command does not execute, and if B does not exist, move a to the directory where B is located and rename it to B. (example 7).

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.