XCOPY is an extension of COPY. You can copy the specified directory together with files and directory structure, but you cannot copy the system files; when using it, at least one is specified for the source disk letter, source target path name, and source file name; when using /S, COPY is performed on all files in the source directory and its subdirectories. Unless the /E parameter is specified, /S will not copy the empty directory. If the /S parameter is not specified, XCOPY will only copy the files of the source directory itself, and will not involve the subdirectories under it. When using the /V parameter, all the copied sectors are tested, but the speed will be reduced.
We cannot count the classics and forget our ancestors. We still need to learn what we should learn, and we still need to forget what we should not forget. Especially DOS batch commands, when developing software or projects, we cannot do without these basic original commands. In this article, let’s learn the parameters and examples of Xcopy
1. Introduction to Xcopy parameters
Command format: XCOPY source [destination] A bunch of optional parameters
Parameter introduction
source Specifies the file to be copied.
destination Specifies the location and/or name of the new file.
/A Only copies files with archived attribute sets, but does not change attributes.
/M Only copy files with archive attribute sets and close archive attributes.
/D:m-d-yCopy files that have changed after the specified date or date. If no date is provided, only those files whose source time is newer than the target time.
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. If any string matches the absolute path of the file to be copied, that file will not be copied.
For example, specifying a string such as \obj\ or .obj will exclude all files under the directory obj or files with the .obj extension.
/P Prompt before creating each target file.
/S Copy directories and subdirectories except empty.
/E Copy directories and subdirectories, including empty ones. 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 Continue to copy even if there is an error.
/I 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 File name is not displayed when copying.
/F Displays the full source and destination file names when copying.
/L Displays the file to be copied.
/G Allows copying of unencrypted files to targets that do not support encryption.
/H also copy hidden and system files.
/R Rewrite read-only files.
/T Creates a directory structure, but does not copy the file. Excludes empty directories or subdirectories. /T /E Includes empty directories and subdirectories.
/U Copy only files that already exist in the target.
/K Copy properties. Normal Xcopy will reset the read-only attribute.
/N Copy with the generated short name.
/O Copy file ownership and ACL information.
/X Copy file audit settings (implicit /O).
/Y Disable prompts to confirm rewriting an existing target file.
/-Y causes a prompt to confirm that an existing target file is overwritten.
/Z Copy network files in restart mode.
2. Introduction to Xcopy command examples
1. Examples of copying files or folders from this machine
Xcopy d:\UpdateFiles e:\123 /s /e /y
Command explanation: Copy all the things contained in the UpdateFiles folder of drive D to the 123 folder of drive E; /s /e /y Parameter description: While copying the file, copy empty directories or subdirectories. If the target path already has the same file, use the overwrite method without prompting.
2. Application examples in LAN
Xcopy \\192.168.0.168\UpdateFiles e:\123 /s /e /y
Command explanation: Copy all the things in the folder named UpdateFiles of the computer 192.168.0.168 to the e:\123 folder of the machine; Parameter description: While copying the file, copy empty directories or subdirectories. If the target path already has the same file, use the overwrite method without prompting.
3. Combined with /d tags, only copy files newer than the target file
If all files in the c:\a folder are the same as those in the d:\a file (modification date and content)
A file under c:\a has been modified or a file has been added by someone else!
Can you write a bat and determine whether the last modification date of each file in the c:\a folder is within the first two days! If yes, copy to the corresponding directory under d:\a (if there was originally, overwrite it), and if not, copy it will not be copied.
@echo off echo y|xcopy c:\a /d /e /r /k d:\a\ pause
After testing, the target file is the same as the source file, no copying will be done. It has indeed reduced the reading and writing of the hard disk to a certain extent.
4. Move all files in directory A to directory B
Move all files in directory A to directory B, and retain the directory structure of directory A; if there are subdirectories under A, the same directory will be created in B, and the files of the corresponding directory will be moved to the same directory structure location of B; (Do not move system files and hidden files)
@echo off rem Copy the directory structure of the specified directory to the target directory,and move the file to the target directory,And preserve the directory structure(Copy empty directory),Do not retain system files and hidden files set ObjPath=\\192.168.1.186\Temp Files\Technical Department\BPD\sourceFiles\ZOFUND set DestPath=E:\EastFax\FFPsourceFiles\sourceFiles\ZOFUND set DestExt=* xcopy /e /c /y "%ObjPath%\%DestExt%" "%DestPath%" del /a /s /q /f "%ObjPath%\"
5. xcopy excludes file copying
@echo off ::xcopy /y /s /e /I /exclude: E:\NetWorkCMDA\CMDA0418\Portals\0 E:\Mu\Portals\0 ::xcopy /y /s /e /I /exclude: C:\Docume~1\wangchao\desktop\MyTest C:\Docume~1\wangchao\desktop\aaa echo Returns the location where the application stores data by default=%APPDATA% echo Return the current directory string=%CD% echo Return the name of the computer=%COMPUTERNAME% echo Returns the exact path to the command line interpreter executable program=%COMSPEC% echo Return the name of the currently logged in user=%USERNAME% echo Returns the name of the domain containing the user account=%USERDOMAIN% echo Return to the location of the current user's configuration file=%USERPROFILE% set myExist=%windir%\TestUncopy set myCommand=%windir%\TestUncopy&echo TestUncopy if not exist %myExist% mkdir %myCommand% set myExist1=%windir%\TestUncopy\a set myCommand1=%windir%\TestUncopy\a&echo TestUncopy\a if not exist %myExist1% mkdir %myCommand1% set myExist2=%windir%\TestUncopy\aa set myCommand2=%windir%\TestUncopy\aa&echo TestUncopy\aa if not exist %myExist2% mkdir %myCommand2% set myExist3=%windir%\TestUncopy\a\b set myCommand3=%windir%\TestUncopy\a\b&echo TestUncopy\a\b if not exist %myExist3% mkdir %myCommand3% set myExist4=%windir%\TestUncopySource set myCommand4=%windir%\TestUncopySource&echo TestUncopySource if not exist %myExist4% mkdir %myCommand4% set myExist5=%windir%\TestUncopy\aaa set myCommand5=%windir%\TestUncopy\aaa&echo TestUncopy\aaa if not exist %myExist5% mkdir %myCommand5% set copyFile=%windir%\system\ if not exist %myExist1%\ copy %copyFile% %myExist1% /y if not exist %myExist2%\ copy %copyFile% %myExist2% /y if not exist %myExist3%\ copy %copyFile% %myExist3% /y if not exist %myExist5%\ copy %copyFile% %myExist5% /y if not exist %myExist1%\ ren %myExist1%\ if not exist %myExist2%\ ren %myExist2%\ if not exist %myExist3%\ ren %myExist3%\ if not exist %myExist5%\ ren %myExist5%\ if not exist %myExist5%\ copy %windir%\system32\ %myExist5% /y if not exist %myExist5%\ ren %myExist5%\ if not exist %myExist5%\ copy %windir%\system32\ %myExist5% /y if not exist %myExist5%\ ren %myExist5%\ if not exist %myExist5%\ copy %windir%\system32\ %myExist5% /y if not exist %myExist5%\ ren %myExist5%\ set OutFile= ::MyDir=\aa\ Excluded folders ::MySubDir=\a\b\ Excluded subfolders ::MyFile= Excluded files ::set MyFile1=.exe Excluded type files set MyDir=\aa\ set MySubDir=\a\b\ set MyFile= set MyFile1=.exe echo %MyDir% > echo %MySubDir% >> echo %MyFile% >> echo %MyFile1% >> xcopy /y /s /e /I /exclude: %windir%\TestUncopy %windir%\TestUncopySource ::if exist %windir%\TestUncopy del %windir%\TestUncopy /s /q&rd %windir%\TestUncopy /s /q &echo del_rd %windir%\TestUncopy ::if exist %windir%\TestUncopySource del %windir%\TestUncopySource /s /q&rd %windir%\TestUncopySource /s /q &echo del_rd %windir%\TestUncopySource ::del start %myExist% start %myExist4% echo Whether to delete(Y/N) set /p shuru= ::if %shuru:~0,1%==y (echo %shuru:~0,1%&goto del) ::if %shuru:~0,1%==Y (echo %shuru:~0,1%&goto del) ::if %shuru:~0,1%==n (echo %shuru:~0,1%&goto End) ::if %shuru:~0,1%==N (echo %shuru:~0,1%&goto End) if %shuru:~0,1%==y (cls&goto del) if %shuru:~0,1%==Y (cls&goto del) if %shuru:~0,1%==n (cls&goto End) if %shuru:~0,1%==N (cls&goto End) pause :del if exist %windir%\TestUncopy del %windir%\TestUncopy /s /q&rd %windir%\TestUncopy /s /q &echo del_rd %windir%\TestUncopy if exist %windir%\TestUncopySource del %windir%\TestUncopySource /s /q&rd %windir%\TestUncopySource /s /q &echo del_rd %windir%\TestUncopySource if exist del :End echo.& ::Line break echo The operation has been completed timeout /t 3 /nobreak cls echo Whether to call again(Y/N)--Y:Call N:quit set /p shuru= if %shuru:~0,1%==y (cls&goto MyCall) if %shuru:~0,1%==Y (cls&goto MyCall) if %shuru:~0,1%==n (cls&goto EndExit) if %shuru:~0,1%==N (cls&goto EndExit) :EndExit exit :MyCall pause
6. Usage of xcopy and EXCLUDE parameters
Example 1: For example, I want to back up a "WebAppBuytoy" directory to "WebAppBuytoy_bak", but I want to exclude the following
The "WebAppBuytoy\product\ProdImages" subdirectory, because it is too large and has no changes and there is no need to backup.
Step 1: Create a new text file called "", and the content is as follows:
product\ProdImages
Step 2, command (including subdirectories, no prompt for overwriting):
xcopy WebAppBuytoy WebAppBuytoy_bak /e /EXCLUDE: /y
Example 2: Publishing .net's Web Project Batch Processing
deploy_web.cmd
xcopy G:\WebSites\BuytoySolutionV2\WebAppBuytoy web /EXCLUDE:web_exclude.txt /i /e /y @rem Will be excluded*.cssFile retrieval xcopy G:\WebSites\BuytoySolutionV2\WebAppBuytoy\App_Themes web\App_Themes /i /e /y @pause
web_exclude.txt:
.cs
.vb
.pdb
.csproj
.
.
.___
.cmd
.rar
\App_Themes\Theme1
\App_Themes\Theme1\
\obj
\obj\
\Properties
\Properties\
\App_Data\
\App_Classes\
Example 3: Publish a .net web project batch, but exclude the product image directory because it is too large and not updated frequently,
Reuse the above exclusion file "web_exclude.txt" and add an exclusion file that excludes product pictures.
"web_exclude_prodImages.txt", so that multiple exclusion file lists are used in one command, using the plus sign "+":
deploy_web_exclude product pictures.cmd
xcopy G:\WebSites\BuytoySolutionV2\WebAppBuytoy web /EXCLUDE:web_exclude.txt+web_exclude_prodImages.txt /i /e /y @rem Will be excluded*.cssFile retrieval xcopy G:\WebSites\BuytoySolutionV2\WebAppBuytoy\App_Themes web\App_Themes /i /e /y @pause
web_exclude_prodImages.txt
\product\ProdImages
\product\ProdImages\
This is the article about the introduction to the use of Xcopy command parameters. For more related Xcopy content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!