Batch processing Getting Started manual for batches Common DOS command posts (attrib, del, copy, xcopy) _dos/bat

Source: Internet
Author: User
Tags file copy

1.2 Learning attrib del copy xcopy command

Learning points:
1. Set file properties: attrib
2. Delete command: Del
3. Copy files: Copy
4. Copying files (clips): xcopy

First, set file properties: attrib

Displays or changes the file properties.
ATTRIB [R | r] [a |-a] [s | s] [H |-h] [[Drive:] [path] filename] [/s [/d]]

Set properties.
-Clears the properties.
R read-only file properties.
A Archive file attribute.
S System file properties.
H hidden file properties.
[Drive:] [Path] [FileName] Specifies the file attributes to be processed.
/S handles matching files in the current folder and its subfolders.
/d also processes folders.


1. To view file properties for a file
Format: ATTRIB [Drive:][path][filename]

Example 1,
attrib d:\ pagefile.sys
View the properties of the D:\ Pagefile.sys file.

2. Modify the properties of the file.
Format: attrib? properties

Example 1,
Attrib–h d:\ Pagefile.sys
Eliminates the "hidden" property of the D:\ Pagefile.sys.

Example 2,
attrib s h d:\ pagefile.sys
Set the system and hide properties for the D:\ Pagefile.sys.

3. Batch file Processing

Example 1,
attrib h d:\123\*.bat/s
The/s parameter allows you to bulk set all bat files under d:\123 and its subdirectories to the hidden property.

Example 2,
attrib h d:\123/s/d
Set the d:\123 and all of its below subdirectories as 123 to the hidden property. Parameter/d must set the file properties at the same time as the specified directory and
All subdirectories under it for file property operations. Parameter/d can be understood as "directory", which means that/d must be used with/s.


Thinking:

What is the difference between "attrib h d:\123/s/d" and "attrib h d:\123\*.*/s/d"?
The former only d:\123 and subdirectories with the same name are set to "hide", while other files and subdirectories do not have "hide".
The latter sets the hidden attribute for all files and subdirectories under D:\123, but the d:\123 directory does not have the Hide attribute set.

Second, delete the command: Del

Deletes one or several files.
DEL [/P] [/F] [/S] [/q] [/a[[:]attributes]] Names
ERASE [/P] [/F] [/S] [/q] [/a[[:]attributes]] Names

names specifies the list of one or more files or directories. Wildcard characters can be used to
Deletes multiple files. If a directory is specified, the
Any files will be deleted.

/p prompts for confirmation before deleting each file.
/F Forces a read-only file to be deleted.
/s Deletes the specified file from all subdirectories.
/q Quiet mode. Confirmation is not required when global wildcard characters are deleted.
/A Select the file you want to delete based on the properties.
Attributes R Read Only file S system files
H hidden file A archive file
-prefix that represents "no"

Basic format: DEL [Drive:][path][filename]

Example 1,
Del D:\123\abc.txt
Delete Abc.txt


/p prompts for confirmation before deleting each file.

Example 2,
del/p D:\123\*.*
Delete all files in the d:\123 directory, if you want it to be deleted before the deletion, we can add/p parameters to prevent accidental deletion.


/s Deletes the specified file from all subdirectories.

Example 3,
DEL/S D:\123\*.*
Deletes all files under the d:\123 directory and its subdirectories.
By using the/s parameter, the DEL command searches for all files of the specified file name in the specified directory (if unspecified, in the current directory) and its subdirectories and deletes
Except.


/q Quiet mode. Confirmation is not required when global wildcard characters are deleted.

Example 4,
DEL/S/q D:\123\*.*
Deletes all files under the d:\123 directory and its subdirectories.
With the/q parameter you do not need to confirm direct deletion, be careful when using this parameter!!


/A Select the file you want to delete based on the properties.

Example 5,
DEL/AR/S D:\123\*.*
Deletes files for all read-only properties under the D:\123 directory and its subdirectories.
Here we choose to delete the file of the specified attribute through the/a:attributes parameter. File attribute attributes, optional r (read only), S (System)
, h (Hidden), A (archive).


Third, copy the file: Copy

Copy can only copy files and cannot copy folders.

1. Replication of individual files

Format: Copy source[drive:][path][filename] [destination [Drive:][path][filename]]
That is, copy the source file (including path and filename) to be copied, the target path [\ filename] of the file copy, when [destination [Drive:][path]
[FileName]] The default is the current directory.

Example 1,
Copy C:\123.txt D:\
Copy the 123.txt to the D:\ directory. If this operation succeeds, the command line window prompts "1 files copied".

Example 2,
Copy C:\123.txt D:\abc.bat
Copy the 123.txt to the D:\ directory and modify it to Abc.bat, where the file name and its format are modified.

Example 3,
Copy. \123
Copy the files from the 123 subdirectories in the current directory to the current directory. It seems a little difficult to understand, hehe, explain: for example, the current directory is
C:\Windows, it has a lot of subdirectories, now it's a subdirectory 123 inside the files are all copied to the current directory C:\Windows, this should be clear
It's white! ~

2. Bulk copy Files

Example 1,
Copy c:\123 D:\ABC
Copy all the files in the c:\123 directory to the D:\ABC directory.

Example 2,
Copy c:\123\*.rm d:\abc/y
Copy all RM-formatted files in the c:\123 directory to the D:\ABC directory, and the same files that are being replicated in the source directory already exist in the destination directory
Name of the file, there will be such as "rewrite x:\xx?" (Yes/no/all): "Such a hint, let you choose to be covered, not covered or all covered,
By using the parameter/y (which can be used when copying a single file or bulk copy), you can implement duplicate files without confirming direct coverage.

3. Merging files
Format: copy/b file 1+ ... File n merged file name

Example 1,
copy/b D:\1.mp3 D:\2.mp3 E:\3.mp3
Combine 1.mp3 and 2.mp3 into 3.mp3.

Example 2,
copy/b D:\1.txt D:\2.mp3
Merge 1.txt and 2.mp3, there's no name for the composite file. By default, the merged filename is the name of the first file in the command.
In this case, the 2.mp3 is merged into the 1.txt.


★ In the tail of the text data hidden in the picture file, the use of other software to edit and save, hidden text data may be lost.
★mp3 files can be continuously played after they are connected using this method.
★ Merge Pictures/songs such binary files must use the/b parameter (binary, binary), or the merge will fail, and the other join IS/a
(A represents ASCII, text files) and can only be used for a merge of plain text. Two parameters cannot be used at the same time, and binary can combine text and binary files.
Text, however, can only merge text.

Iv. copy files (clips): xcopy

Copy files and directory trees.
XCOPY source [Destination] [/a |/M] [/d[:d ate]] [/p] [/S [/e]] [/v] [/w]
[/C] [I] [/Q] [/F] [/L] [/g] [/h] [/R] [/T] [/u]
[/k] [/n] [/O] [/x] [/y] [/-y] [/z]
[/exclude:file1[file2][file3] ...]

Source
Required. Specifies the location and name of the file to be copied. The parameter must contain a drive or path.
Destination
can be omitted. Specifies the target of the file to be copied. This parameter can contain a drive letter and a colon, a directory name, a file name, or a combination of them.
If you omit the destination,xcopy command, copy the file to the current directory.


Xcopy can use too many parameters, here only select a few commonly used to say.

/S to copy non-null directories and subdirectories. If omitted, the/s,xcopy will work in a directory.

Example 1,
XCOPY/S d:\123 E:\kkk\
Copy all files (clips) to E:\KKK in the d:\123 directory, excluding empty subdirectories. (Xcopy does not copy hidden or system files by default)


/e Copies all subdirectories, including empty directories. Use the/e,/s, and/T command-line options at the same time.

Example 2,
xcopy/e d:\123 E:\kkk\
Copy all files (clips) to E:\KKK in the d:\123 directory, including empty subdirectories. (Xcopy does not copy hidden or system files by default)


/h copy files that have hidden and system file attributes. xcopy does not replicate hidden or system files by default.

Example 3,
xcopy/e/h d:\123 E:\kkk\
Copy all files (clips) to E:\KKK in the d:\123 directory, including empty subdirectories. After adding the/h parameter, xcopy copies the hidden or system files


/T replicates only the subdirectory structure (that is, the directory tree) and does not copy the files. To copy an empty directory, you must include the/e option.


/y prevents you from prompting you to confirm that you want to overwrite an existing destination file.
The rewrite X:\XXX (yes/no/all) appears when the target directory already exists with the same filename as the file that is about to be copied in the source directory.
Such a hint, so that you choose to overwrite, not cover or full coverage, through the parameter/y, you can achieve duplicate file name without the need to confirm direct coverage.


★ Note whether the specified destination is a file or directory.
If destination does not contain an existing directory and does not end with a backslash (\), the following message appears:

Does destination specify a file name
or directory name on the target
(F = file, D = directory)?

The system will ask you
Whether the target X:\XXX is a filename or directory name
(F = file, D = directory)?
If you want to copy one or more files to a file, press F. If you want to copy one or more files to a directory, press D.


thinking:

What's the difference between xcopy/e d:\123 e:\kkk\ and xcopy/e d:\123 e:\kkk?
Both are replicated in the d:\123 directory all Files (folders) to E:\KKK, including empty subdirectories, but the former does not ask you
Whether the target e:\kkk is a filename or directory name
(F = file, D = directory)?

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.