xcopy implements batch copy files or folders _dos/bat

Source: Internet
Author: User
Tags file copy goto naming convention
Xcopy is a very useful Doc command and should learn to learn!
Can be implemented with Xcopy, for example:
C:\>xcopy c:\ppt\*.* D:\ppt\/s/e
The meaning of this order is to copy all the PPT folders under C disk to D disk.
XCOPY also has a number of functions that are added to the parameters to complete. The effect of the above/s/e parameters is the root directory and the empty directory are copied past,
Some examples of use and parameters are described below:
1, such as simply copy E:\ All files on disk to D:\ On the disk, enter "xcopy E:\*.* D:/s/h" on the line! If in the process of copying, you do not want him to copy the file! Then press the keyboard hotkey "Ctrl" + "Pause/break" two hot Keys to interrupt replication.
2. If you want to put e:\ Disk all the files copied to the D:\ disk, divided into today to copy a little, tomorrow and then copy some, the day after tomorrow and then copy some. Or for some reason the last time you didn't copy it, you want to copy it today. (This is often the case in the copy file) What's the best thing to do?
Then enter "Xcopy E:\*.* D:/s/h/d/y" on the line. He can find out that those files have been copied, and those files have not been copied.
3, of course, we will also encounter this situation, some files we have modified it! There is a new version on the Web. The original copy of the file we need to update the timely. So how do you sync updates? Of course, we can copy the latest good documents to the past, which is also a solution.
If there are many changes to the file, you will not remember that the document is updated. So much of the original copy of the file to be updated, to replicate the past, is not a province of energy, and error prone and some documents are forgotten!
That is the same as the above input "xcopy E:\*.* D:/s/h/d/y" on the line!
4, there is also a situation we often encounter, because copying a file is an error or the file is in use, and the replication work is stopped (for example, copying Windows XP on C disk) we want to skip over an error file and a file that is in use and continue copying other files.
Adding one more parameter "/C" is "Xcopy E:\*.* D:/s/h/d/c/y" On the line!
5, sometimes we want XCOPY to become automatic replication, and after the copy is completed, you can set up a batch file, new text document, renamed to Xcopy.bat of course, the extension is originally TXT format to be renamed BAT in this XCOPY. BAT input
xcopy E:\*.* D:/s/h/c/y
Shutdown-s
Then double-click Xcopy.bat to run it, you can go out and play at this time. The computer copies the backup and completes the file itself and shuts down the computer automatically.
XCOPY source [destination] parameter (such as/s/e)
SOURCE specifies the file to copy.
destination Specifies the location and/or name of the new file.
/A copies only files that have archived attribute sets.
But do not change attributes.
/M copies only files that have archived attribute sets.
and close the archive attribute.
/d:m-d-y copies files that have changed after a specified date or a specified date.
If no date is provided, only those source times are copied
A new file than the target time.
/EXCLUDE:FILE1[+FILE2][+FILE3] ...
Specifies a list of files that contain strings. If there is any
The absolute path to the string and the file to be copied
Match, that file will not be copied.
For example, specifying a string such as \obj\ or. obj excludes
All files under directory obj or with
The file for the. obj extension.
/p prompts before each target file is created.
/S Copy directories and subdirectories, except for empty.
/e Copies directories and subdirectories, including empty.
Same as/s/e. Can be used to modify/T.
/V verifies each new file.
/w prompts you to press the key before copying.
/C Continue copying even if there are errors.
/I if the target does not exist, and is copying more than one file,
It is assumed that the target must be a directory.
/q does not display the file name when copying.
/F Displays the full source and destination file names when copying.
/L Displays the files to be copied.
/g allows files that have not been encrypted to be copied to the
The target of encryption is not supported.
/h also copies hidden and system files.
/R overwrites read-only files.
/T Creates a directory structure, but does not copy files. No
Include an empty directory or subdirectory. /T/E includes
Empty directories and subdirectories.
/U copies only files that already exist in the target.
/k replication Properties. The general Xcopy resets the read-only property.
/n is copied with the generated short name.
/o Copy file ownership and ACL information.
/x Copy file audit settings (implied/O).
/y Suppresses prompts to confirm overwriting a
An existing target file.
/-y causes a prompt to confirm the overwrite of a
An existing target file.
/z The network file in restart mode.

Xcopy
Copy files and directories, including subdirectories.
Grammar
xcopy Source [destination] [/w] [/P] [/C] [/v] [//////////////////////[///////////////////////L] h] [{/a|/m}] [/n] [o] [/x] [/exclude:file1[+[file2]][+[file3]] [{/y|/-y}] [/z]
Parameter Source is required. Specifies the location and name of the file to be copied. The parameter must contain a drive or path. destination 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. /w displays the following message and waits for your response before you start copying files:
Press any key to begin copying file (s)
/p prompts you to confirm that you want to create each destination file. /C ignores errors. /V validates each file when writing to the destination file to ensure that the destination file is identical to the source file. /q suppresses xcopy message display. /F Displays the source and destination file names when copying. /L displays a list of files to copy. /g creates a decrypted target file. /D[:MM-DD-YYYY] Copies only those source files that have changed after a specified date or a specified date. If you do not include the MM-DD-YYYY value, xcopy copies all new Source files that are newer than the existing destination file. This command-line option allows you to update files that have changed. /u copies only the files that are already in the destination from source. /I if Source is a directory or contains wildcard characters, and destination does not exist, Xcopy assumes that destination specifies the directory name and creates a new directory. Xcopy then copies all the specified files to the new directory. By default, Xcopy prompts you to specify whether destination is a file or a directory. /s replicates non-empty directories and subdirectories. If omitted, the/s,xcopy will work in a directory. /e Copies all subdirectories, including empty directories. Use the/e,/s, and/T command-line options at the same time. /t copies 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 command-line option. /k copies the file and retains the property in the destination file if the source file has a read-only property. By default, Xcopy deletes read-only properties. /r copies read-only files. /h copy files that have hidden and system file attributes. By default, Xcopy does not replicate hidden or system files. /A copies only those source files that have the archive file property settings. /A does not modify the archive file properties of the source file. For information about how to set archive file properties by using attrib, see. /m copies the source file with the Archive file property settings. Unlike/A,/m closes the archive file attribute of the file specified in the source. For information about how to set archive file properties by using attrib, see. /n Creates a copy using an NTFS short file or directory name. You need/n when you copy a file or directory from an NTFS volume to a FAT volume or when the target file system requires a FAT file system naming convention (that is, 8.3 characters). The destination file system can be FAT or NTFS. /o Copy file ownership and discretionary access control List (DACL) information. /x Replication file auditing settings and system access control lists (SACL) information (including/O). /EXCLUDE:FILENAME1[+[FILENAME2]][+[FILENAME3]] Specifies a list of files that contain strings. /y prevents you from prompting you to confirm that you want to overwrite an existing destination file. /-y prompts you to confirm that you want to overwrite the existing destination file. /z is replicated over the network in a restartable mode. /? Display Help at the command prompt. Note Use/V
XOX
Using/exclude
Lists each string in a separate row for each file. If any of the strings listed match any part of the absolute path of the file to be copied, the file is excluded from the replication process. For example, if the string "\obj\" is specified, all files under the OBJ directory are excluded. If the string ". obj" is specified, all files with the. obj extension are excluded.
Using/z
If a connection is lost during replication (for example, if the server used for the connection is offline), the replication process is restored after the connection is reconnected. /z also displays the percentage of replication operations completed per file.
using/y in Copycmd environment variables
You can use/y in copycmd environment variables. Use/-y on the command line to override the command. By default, you are prompted to overwrite unless you run copy from within a batch script.
Copy an encrypted file
Copying an encrypted file to a volume that does not support EFS can result in an error. You should first decrypt the file or copy the file to a volume that supports EFS.
Ancillary files
To attach a file, specify a single destination file, multiple source files (using wildcard characters or file 1 + file 2 + file 3 format).
Default value for Destination
If you omit the destination,xcopy command, copy 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 appears:
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 a file, press F. If you want to copy one or more files to a directory, press D.
Using the/I command-line option suppresses the display of this message, which causes Xcopy to determine that the destination is a directory when the source is multiple files or a directory.
To set the Archive property of a destination file using the xcopy command
The xcopy command creates a file with an archive property setting, regardless of whether this property is set in the source file. For more information about file properties and attrib, see.
Compare Xcopy and diskcopy
If the disk's subdirectories contain files, and you want to copy them to a disk with a different format, use the xcopy command instead of diskcopy. Because the diskcopy command is a track to copy a disk, you need the same format for both the source and destination disks. The xcopy command does not have this requirement. You typically use xcopy unless you need a full copy of the disk image.
Xcopy's exit code
To handle the exit code returned by Xcopy, use the errorlevel parameter on the IF command line of the batch program. For an example of a batch program that uses "if" to handle exit codes, see. The following table lists each exit code and description.
Exit code Description 0 File copy no error. 1 No files were found to copy. 2 users terminated xcopy by pressing CTRL + C. 4 An initialization error occurred. There is not enough memory or disk space, or an invalid drive name or syntax was entered on the command line. 5 A disk write error has occurred. Example
To copy all files and subdirectories (including all empty subdirectories) to drive B from drive A, 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 using the files changed after December 29, 1993 in the \rawdata directory, type:
xcopy \rawdata \reports/d:12-29-1993
To update all files that exist in \reports in the previous example, regardless of the date, type:
xcopy \rawdata \reports/u
If you want to obtain only the list of files that you want to copy from the previous command, and do not copy the files, type:
xcopy \rawdata \reports/d:12-29-1993/l > Xcopy.out
File Xcopy.out lists all the files that you want to copy.
To copy the \customer directory and all subdirectories to the directory on network drive H: \\Public\Address, keep the read-only property and prompt you when creating a new file on H:, type:
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, and suppresses the display of messages to display when the new directory is created, adding the/I command-line option as follows:
xcopy \customer h:\public\address/s/e/k/p/i
You can create a batch program to perform an XCOPY operation and use the IF batch command to handle an exit code when an error occurs. For example, the following batch program uses the replaceable xcopy source and target parameters:
Copy Code code as follows:

@echo off
REM Copyit. BAT transfers all files in all subdirectories of
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 program to copy all files in the C:\Prgmcode directory and its subdirectories to drive B, type:
Copyit C:\prgmcode B:
The command interpreter replaces%1 with B with C:\Prgmcode:. For%2, then use the Xcopy and/e and/s command-line options. If Xcopy encounters an error, the batch program reads the exit code and moves to the label indicated in the appropriate IF ERRORLEVEL statement, and then displays the corresponding message and exits the batch program.

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.