Xcopy implements batch copy of files or folders

Time:2020-4-16

Xcopy is a very useful doc command. You should learn!
It can be implemented with xcopy, for example:
C:\>xcopy C:\ppt\*.* D:\ppt\ /s /e
This command means to copy all the PPT folders under the C disk to the D disk
Xcopy also has many functions, which are completed by adding parameters. The / S / E parameter above is used to copy subdirectories and empty directories,
Some examples and parameters are as follows:
1. If you simply copy all the files on the E: \ disk to the D: \ disk, enter “xcopy: \ *. * D: / S / h”! If in the process of copying, you don’t want him to copy files! Press the keyboard hotkey “Ctrl” + “pause / break” to interrupt the copy.
2. If you want to copy all the files on the E: \ disk to the D: \ disk, you can copy them today, tomorrow, and the day after tomorrow. Or for some reason, I didn’t finish copying last time. I want to continue copying today. (this situation often occurs in copying files) what can I do?
Enter “xcopy e: \ *. * D: / S / h / D / Y”. He can find out that those files have been copied, and those files have not been copied.
3. Of course, we also encounter this situation. We have modified some documents! There is the latest version on the net. We need to update the original backup file in time. How can I synchronize updates? Of course, we can copy the latest good documents, which is also a solution.
If there are many revised documents, I can’t remember that they have been updated. So many original backup files need to be updated and copied. It’s not a labor-saving job, and it’s easy to make mistakes and forget some files!
Just as above, just input “xcopy: \ *. * D: / S / h / D / Y”!
4. There is another situation that we often encounter, because copying a file is wrong or the file is in use, and we stop copying (for example, copying windows xp on Disk C). At this time, we want to skip a wrong file and a file in use and continue copying other files.
Add one more parameter “/ C” as “xcopy: \ *. * D: / S / h / D / C / Y”!
5. Sometimes we want xcopy to become automatic copying, and after copying, we can turn off the computer, create a batch file, create a new text document, and change its name to xcopy.bat. Of course, the extension was originally in the format of TXT, and we need to change its name to bat, and enter it in this xcopy.bat
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 will copy the backup files by itself and then automatically shut down the computer.
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 only copies files with archive property sets,
But do not change the properties.
/M only files with archive property sets are copied,
And close the archive properties.
/D: M-d-y copies files that change on or after a specified date.
If no date is provided, only those source times are copied
Files that are newer than the target time.
/EXCLUDE:file1[+file2][+file3]…
Specifies the list of files with strings. If there is any
String and the absolute path of the file to be copied
Match, that file will not be copied.
For example, specifying a string such as \ obj \ or. Obj will exclude
All files under directory obj or with
. obj extension.
/P prompt before creating each target file.
/S copies directories and subdirectories, except for the empty ones.
/E copy directories and subdirectories, including empty.
Same as / S / E. Can be used to modify / T.
/V verify each new file.
/W prompts you to press the key before copying.
/C continues to copy even if there are errors.
/If the target does not exist and more than one file is being copied,
It is assumed that the target must be a directory.
/Q do not display the filename when copying.
/F displays the full source and destination file names when copying.
/L shows the files to copy.
/G allows files that are not encrypted to be copied to
Encrypted targets are not supported.
/H also copies hidden and system files.
/R overwrite read-only file.
/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 only copies files that already exist in the destination.
/K copy properties. Normal xcopy resets the read-only property.
/N copies with the generated short name.
/O copy file ownership and ACL information.
/X copy file audit settings (implicit / O).
/Y suppresses prompting to confirm overwriting a
Existing target file.
/-Y causes a prompt to confirm overwriting a
Existing target file.
/Z copies network files in restart mode.

Xcopy
Copy files and directories, including subdirectories.
grammar
xcopy Source [Destination] [/w] [/p] [/c] [/v] [/q] [/f] [/l] [/g] [/d[:mm-dd-yyyy]] [/u] [/i] [/s [/e]] [/t] [/k] [/r] [/h] [{/a|/m}] [/n] [/o] [/x] [/exclude:file1[+[file2]][+[file3]] [{/y|/-y}] [/z]
The parameter Source is required. Specifies the location and name of the file to copy. The parameter must contain a drive or path. Destination specifies the destination of the file to copy. This parameter can contain the drive letter and colon, directory name, file name, or a combination of them. /W the following message is displayed and waiting for your response before starting to copy the file:
Press any key to begin copying file(s)
/P prompts you to confirm that you want to create each target file. /C ignore the error. /V validates each file as it writes to the destination file to ensure that the destination file is exactly the same as the source file. /Q suppress xcopy messages. /F displays the source and destination file names when copying. /L displays a list of files to copy. /G creates the decrypted target file. /D [: MM DD yyyy] copies only those source files that have changed on or after the specified date. If the MM DD yyyy value is not included, xcopy copies all source files that are newer than the existing destination file. This command line option allows you to update changed files. /U copies only files that already exist in the destination from source. /If the source is a directory or contains wildcards, 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 the destination is a file or a directory. /S copies 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. /Tcopy only the subdirectory structure (that is, the directory tree), not the files. To copy an empty directory, you must include the / E command line option. /K copies the file, and if the source file has a read-only attribute, the attribute is retained in the target file. By default, xcopy removes read-only properties. /R copy a read-only file. /H copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files. /A copies only those source files that have the archive file property settings. /A does not modify the archive properties of the source file. For information on how to set archive properties by using attrib, see “.”. /M copies the source file with the archive file property settings. Unlike / A, / M turns off the archive properties for the file specified in the source. For information on how to set archive properties by using attrib, see “.”. /N create a copy using the NTFS short file or directory name. / N is required to 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 target file system can be fat or NTFS. /O copy file ownership and 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]] specifies the list of files that contain strings. /Y do not prompt you to confirm that you want to overwrite the existing target file. /-Y prompts you to confirm that you want to overwrite the existing target file. /Z replicates over the network in restartable mode. /? display help at the command prompt. Comment use / V
XOX
Use / exclude
Lists each string in a separate line 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 you specify the string “\ obj \”, all files in 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 to connect is offline), the replication process resumes after the connection is reestablished. /Z also shows the percentage of copy operations completed for each file.
Use / Y in copycmd environment variable
You can use / Y in the copycmd environment variable. 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 encrypted files
Copying encrypted files to a volume that does not support EFS can cause errors. You should first decrypt the file or copy the file to a volume that supports EFS.
Ancillary document
To attach a file, specify a single target file, multiple source files (using wildcard characters or the 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 directory
If the 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 one 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 the message, resulting in xcopy assuming that the target is a directory in the case of multiple files or a directory.
Use xcopy command to set the archive properties of destination file
The xcopy command creates a file with archive property settings, regardless of whether this property is set in the source file or not. For more information about file properties and attribs, see “.”.
Compare xcopy and DiskCopy
If the subdirectory of the disk contains files, to copy them to a disk with a different format, use the xcopy command instead of DiskCopy. Because the DiskCopy command copies disks one track after another, the format of the source disk and the target disk must be the same. The xcopy command does not have this requirement. Usually use xcopy unless you need a full 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 program. For an example of a batch program that uses “if” to process exit codes, see “.”. The following table lists each exit code and description.
The exit code indicates that there is no error in copying the 0 file. 1 no files found to copy. 2 user presses Ctrl + C to terminate xcopy. 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 occurred. 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 from the previous example, add the / h command line option as follows:
xcopy a:b:/s /e /h
To update files in the \ reports directory with 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 the \ reports in the above example, regardless of date, type:
xcopy \rawdata \reports /u
If you want to get only a list of files to copy from the previous command, instead of copying files, type:
xcopy \rawdata \reports /d:12-29-1993 /l > xcopy.out
The file Xcopy.out lists all the files to copy.
To copy the \ customer directory and all subdirectories to the directory \ \ public \ address on network drive H:, 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 xcopy creates the \ address directory when it does not exist, and suppress the message to be displayed when creating a new directory, add 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 xcopy operations, and use the if batch command to process the exit code when an error occurs. For example, the following batch programs use replaceable xcopy source and target parameters:

Copy codeThe code is 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 the 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 will replace% 1 and 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 goes to the label indicated in the corresponding if errorlevel statement, then displays the corresponding message and exits the batch program.

Recommended Today

Big data Hadoop — spark cluster deployment (standalone)

catalogue 1、 Spark overview 2、 Operation mode of spark 1) Standalone (explained in this chapter) 2)Mesos 3) Yarn (recommended) 4) K8s (new mode) 3、 Standalone mode operation mechanism 1) Standalone client mode 2) Standalone cluster mode 4、 Spark cluster installation (standalone) 1) Machine and role division 2) Install JDK environment on three machines 3) Download […]