I don't know how many other people will use the batch processing command. There are some convenient and practical functions.
Xcopy also has many functions, which are completed by adding parameters. The above/S/e parameters are used to copy all subdirectories and empty directories. Some examples and parameter descriptions are as follows:
1. If you just copy all files on the E:/disk to the D:/disk, enter "xcopy E:/*. * D:/S/H! If you do not want to copy files during the copy process! Press the keyboard key "Ctrl" + "Pause/Break" to interrupt replication.
2. If you want to copy all the files on the E:/disk to the D:/disk, copy them one by one today, copy them one by one tomorrow, and then copy them the next day. Or, for some reason, the last copy was not completed, and I want to copy it again today. (This is often the case when copying files.) What should I do?
Enter "xcopy E:/*. * D:/S/H/D/y. He can find out that the files have been copied and those files have not been copied.
3. Of course we will also encounter this situation. We have modified some files! The latest version is available on the Internet. We need to update the original backup file in time. So how can we synchronize updates? Of course, we can copy the latest good files. This is also a solution.
If there are many modified files, you will not be able to remember that the file has been updated. So many original backup files must be updated and copied. This is not a task that saves effort and is prone to errors and some files are forgotten!
Enter "xcopy E:/*. * D:/S/H/D/y" just like above!
4. There is also a situation that we often encounter because an error occurs when copying a file or the file is in use, and the copy operation is stopped (for example, copying Windows XP on a C drive) at this time, we want to skip an incorrect file and a file in use and continue copying other files.
Add one more parameter "/C", that is, "xcopy E:/*. * D:/S/H/D/C/y!
5. Sometimes we want to change xcopy to automatic copy, and shut down the computer after the copy is complete, we can create a batch file, create a new text file, and rename it xcopy. of course, the extension of BAT is originally in TXT format and should be renamed to bat in this xcopy. input in bat
Xcopy E:/*. * D:/S/H/C/y
Shutdown-S
Double-click xcopy. BAT to run it. You can go out and play now. The computer automatically copies the backup file and closes the computer.
Xcopy source [destination] parameters (such as/S/E)
Source specifies the file to be copied.
Destination specifies the location and/or name of the new file.
/A only Copies files with an archived surname set,
But does not change the surname.
/M only Copies files with an archived surname set,
Disable the last name of the archive.
/D: M-D-Y: copy the objects that have changed since the specified date or date.
If no date is provided, only the source time is copied.
A file that is newer than the target time.
/Exclude: file1 [+ file2] [+ file3]...
List of objects containing strings. If any
Absolute path of the string and the file to be copied
The file will not be copied.
For example, strings such as/obj/or. OBJ are excluded.
All files under the OBJ directory or
File with the. OBJ extension.
/P prompt before creating each target file.
/S copies directories and subdirectories, except empty.
/E: Copy directories and subdirectories, including empty ones.
Same as/S/e. It can be used to modify/t.
/V verify each new file.
/W prompts you to press the button before copying.
/C continues copying even if an error occurs.
/I if the target does not exist, copy more than one file,
It is assumed that the target must be a directory.
The file name is not displayed during/Q replication.
/F indicates the complete source and target file names.
/L displays the file to be copied.
/G allows copying unencrypted files
Encryption targets are not supported.
/H also copies hidden and system files.
/R rewrite the read-only file.
/T create directory structure, but do not copy files. No
Including empty directories or subdirectories. /T/e Includes
Empty directories and subdirectories.
/U only Copies files that already exist in the target.
/K. Generally, xcopy will reset the read-only surname.
/N is copied with the generated short name.
/O copy the file ownership and ACL information.
/X copy file audit settings (implicit/O ).
/Y forbidden prompt to confirm rewriting of one
Existing target file.
/-Y causes a prompt to confirm rewriting of
Existing target file.
/Z copies network files in restart mode.
Xcopy
Copy files and directories, including subdirectories.
Syntax
Xcopy source [destination] [/W] [/P] [/C] [/V] [/q] [/F] [/L] [/g] [/d [: mm-dd-yyyy] [/s [/E] [/T] [/K] [/R] [/h] [{/A |/m}] [/n] [/o] [/X] [/exclude: file1 [+ [file2] [+ [file3] [{/Y |/-y}] [/Z]
Parameters
Source
Required. Specifies the location and name of the file to be copied. This parameter must contain the drive or path.
Destination
Specifies the target of the file to be copied. This parameter can contain drive letters, colons, directory names, file names, or combinations of them.
/W
The following message is displayed before you start copying a file and waits for your response:
Press any key to Begin copying file (s)
/P
You are prompted to confirm whether to create each target file.
/C
Ignore errors.
/V
Verify each file when writing the target file to ensure that the target file is exactly the same as the source file.
/Q
Disable xcopy message display.
/F
The source file name and target file name are displayed during copy.
/L
Displays the list of files to be copied.
/G
Create the target file for decryption.
/D [: Mm-dd-yyyy]
Only the source files changed after the specified date or date are copied. If the value of MM-dd-yyyy is not included, xcopy copies all the new source files than the existing destination files. This command line option allows you to update changed files.
/U
Only copies existing files in destination from source.
/I
If source is a directory or contains wildcards, but destination does not exist, xcopy assumes that destination specifies the directory name and creates a new directory. Then, xcopy copies all specified files to the new directory. By default, xcopy will prompt you to specify whether the destination is a file or a directory.
/S
Copy non-empty directories and subdirectories. If/s is omitted, xcopy will work in a directory.
/E
Copy all subdirectories, including empty directories. Use the/e,/s, and/T command line options at the same time.
/T
Only copy the sub-directory structure (that is, the directory tree) without copying files. To copy an empty directory, the/e command line option must be included.
/K
Copy the file. If the source file has a read-only surname, keep the surname in the target file. By default, xcopy deletes the read-only surname.
/R
Copy a read-only file.
/H
Copy a file with a hidden or system file name. By default, xcopy does not copy hidden or system files.
/
Copy only the source files with the name of the archive file. /A does not modify the name of the archive file of the source file. For information about how to use attrib to set the name of an archive file, see "".
/M
Copy the source file with the name of the archive file. Unlike/a,/M disables the name of the archive file of the specified file in the source. For information about how to use attrib to set the name of an archive file, see "".
/N
Use the NTFS short file or directory name to create a copy. Copy a file or directory from the NTFS Volume to the fat volume, or/N is required when the target file system requires the FAT file system Naming Convention (that is, 8.3 characters. The target file system can be fat or NTFS.
/O
Copy the File Ownership and the freely selected Access Control List (DACL) information.
/X
Copy File Audit settings and system access control list (SACL) information (including/O ).
/Exclude: filename1 [+ [filename2] [+ [filename3]
List of objects containing strings.
/Y
Do not prompt you to overwrite the existing target file.
/-Y
You are prompted to confirm that you want to overwrite the existing target file.
/Z
Network replication is enabled in rebootable mode.
/?
Display help at the command prompt.
Note
Use/V
Xox
Use/exclude
Lists each string in a separate row of each file. If any string listed matches any part of the absolute path of the file to be copied, the file will be excluded from the copy process. For example, if the string "/obj/" is specified, all files in the OBJ directory are excluded. If the string ". OBJ" is specified, all files with the. OBJ extension are excluded.
Use/Z
If the connection is lost during the replication process (for example, if the server used for connection is offline), the replication process will be restored after the connection is established again. /Z also displays the percentage of copies completed for each file.
Use/y in copycmd Environment Variables
You can use/Y in the copycmd environment variable. Use/-y on the command line to overwrite the command. By default, you will be prompted to overwrite, unless you run copy from the batch script.
Copy Encrypted Files
Copying an encrypted file to a volume that does not support EFS may cause an error. Files should be decrypted or copied to EFS-supported volumes first.
Ancillary documents
To attach a file, specify a single target file and multiple source files (using wildcards or file 1 + file 2 + file 3 Format ).
Default Value of destination
If destination is omitted, the xcopy Command copies the file to the current directory.
Specify whether destination is a file or a directory
If destination does not contain an existing Directory and does not end with a backslash (/), the following message is displayed:
Does destination specify a file name
Or directory name on the target
(F = file, D = directory )?
If you want to copy one or more files to one file, press F. To copy one or more files to a directory, press d.
You can use the/I command line option to suppress the display of the message, so that xcopy determines that the target is a directory when the source is multiple files or one directory.
Use the xcopy command to set the archiving surname of the destination file
The xcopy command creates a file with the archive surname settings, regardless of whether the source file has this surname set. For more information about the file surname and attrib, see "".
Compare xcopy and diskcopy
If the subdirectory of a disk contains files and you want to copy them to a disk of different formats, use the xcopy command instead of diskcopy. Because the diskcopy Command copies a disk from a track to a track, the format of the source disk and the target disk must be the same. The xcopy command does not have this requirement. In general, use xcopy unless you need a complete copy of the disk image.
Exit code of xcopy
To process the exit code returned by xcopy, use the errorlevel parameter on the if command line of the batch processing program. For examples of batch processing programs that use "if" to process exit codes, see "". The following table lists each exit code and description.
Exit Code Description
There is no error in copying 0 files.
1. the file to be copied is not found.
2. The xcopy is terminated by pressing CTRL + C.
4. An initialization error occurs. There is not enough memory or disk space, or an invalid drive name or syntax is entered on the command line.
5. A disk write error occurs.
Example
To copy all files and subdirectories (including all empty subdirectories) from drive a to drive B, type:
Xcopy A: B:/S/E
To include any system or hidden files in the previous example, add the/H command line option as follows:
Xcopy A: B:/S/e/h
To update the files in the/reports directory changed after January 1, December 29, 1993 in the/rawdata directory, type:
Xcopy/rawdata/reports/D: 12-29-1993
To update all files in/reports in the previous example, regardless of the date, type:
Xcopy/rawdata/reports/u
If you only want to obtain the list of files to be copied by the previous command, instead of copying files, type:
Xcopy/rawdata/reports/D: 12-29-1993/L> xcopy. Out
File xcopy. out lists all the files to be copied.
Copy the/customer directory and all subdirectories to the directory on the network drive H: // public/address, retain the read-only surname, and prompt you when creating a new file in H, enter:
Xcopy/customer H:/public/address/S/e/k/P
To issue the previous command, make sure that xcopy creates the directory when the/address directory does not exist. At the same time, suppress the messages to be displayed when the new directory is created, add the/I command line option as follows:
Xcopy/customer H:/public/address/S/e/k/P/I
You can create a batch processing program to execute the xcopy operation, and use the if batch processing command to process the exit code in case of an error. For example, the following batch processing programs use replaceable xcopy source and target parameters:
@ Echo off
Rem copyit. Bat transfers all files in all subdirectories
Rem the source drive or directory (% 1) to the destination
Rem drive or directory (% 2)
Xcopy % 1% 2/S/E
If errorlevel 4 goto lowmemory
If errorlevel 2 goto abort
If errorlevel 0 goto exit
: Lowmemory
Echo insufficient memory to copy files or
Echo invalid drive or command-line syntax.
Goto exit
: Abort
Echo you pressed Ctrl + C to end the copy operation.
Goto exit
: Exit
To use this batch to copy all files in the C:/prgmcode directory and Its subdirectories to drive B, type:
Copyit C:/prgmcode B:
This command interpreter replaces % 1 with B with C:/prgmcode :. For % 2, use the xcopy and/E and/s command line options. If xcopy encounters an error, the batch processing program reads the exit code and forwards it to the label indicated in the corresponding if errorlevel statement, then displays the corresponding message and exits the batch processing program.