xcopy
Copies files and directories, including subdirectories. Windows commands reference
On Windows 5 Sigma rules name it File xcopy.exe
Windows
Copies files and directories, including subdirectories. For examples of how to use this command, see Examples. - Using /z If you lose your connection during the copy phase (for example, if the server going offline severs the connection), it resumes after you reestablish the connection. /z also displays the percentage of the copy operation completed for each file. - Using /y in the COPYCMD environment variable. You can use /y in the COPYCMD environment variable. You can override this command by using /-y on the command line. By default, you're prompted to overwrite. - Copying encrypted files Copying encrypted files to a volume that doesn't support EFS results in an error. Decrypt the files first or copy the files to a volume that does support EFS. - Appending files To append files, specify a single file for destination, but multiple files for source (that is, by using wildcards or file1+file2+file3 format). - Default value for _destination_ If you omit _destination_, the xcopy command copies the files to the current directory. - Specifying whether _destination_ is a file or directory If _destination_ doesn't contain an existing directory and doesn't end with a backslash (\), the following message appears: Press F if you want the file or files to be copied to a file. Press D if you want the file or files to be copied to a directory. You can suppress this message by using the /i command-line option, which causes xcopy to assume that the destination is a directory if the source is more than one file or a directory. - Using the xcopy command to set archive attribute for _destination_ files The xcopy command creates files with the archive attribute set, whether or not this attribute was set in the source file. For more information about file attributes and attrib, see Related links. - Comparing xcopy and diskcopy If you have a disk that contains files in subdirectories and you want to copy it to a disk that has a different format, use the xcopy command instead of diskcopy. Because the diskcopy command copies disks track by track, your source and destination disks must have the same format. The xcopy command doesn't have this requirement. Use xcopy unless you need a complete disk image copy. - Insufficient memory error …
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:FileName1[+[FileName2]][+[FileName3]]] [{/y | /-y}] [/z] [/b] [/j] [/compress]
1. To copy all the files and subdirectories (including any empty subdirectories) from drive A to drive B, type
xcopy a: b: /s /eIdentify/sCopies directories and subdirectories, unless they're empty. Windows commands reference/eCopies all subdirectories, even if they're empty. Windows commands reference2. To include any system or hidden files in the previous example, add the /h command-line option as follows
xcopy a: b: /s /e /hIdentify/sCopies directories and subdirectories, unless they're empty. Windows commands reference/eCopies all subdirectories, even if they're empty. Windows commands reference/hCopies files with hidden and system file attributes. Windows commands reference3. To update files in the \Reports directory with the files in the \Rawdata directory that have changed since December 29, 1993, type
xcopy \rawdata \reports /d:12-29-1993Identify/dCopies source files changed on or after the specified date only. Windows commands reference4. To update all the files that exist in \Reports in the previous example, regardless of date, type
xcopy \rawdata \reports /uIdentify/uCopies files from _source_ that exist on _destination_ only. Windows commands reference5. To obtain a list of the files to be copied by the previous command (that is, without actually copying the files), type
xcopy \rawdata \reports /d:12-29-1993 /l > xcopy.outIdentify/dCopies source files changed on or after the specified date only. Windows commands reference/lGenerates a list of files that are to be copied, but doesn't actively copy the files. Windows commands reference6. To copy the \Customer directory and all subdirectories to the directory \\\\Public\Address on network drive H:, retain the read-only attribute, and be prompted when a new file is created on H:, type
xcopy \customer h:\public\address /s /e /k /pIdentify/sCopies directories and subdirectories, unless they're empty. Windows commands reference/eCopies all subdirectories, even if they're empty. Windows commands reference/kCopies files and retains the read-only attribute on _destination_ files if present on the _source_ files. Windows commands reference/pPrompts you to confirm whether you want to create each destination file. Windows commands reference7. To issue the previous command, ensure that xcopy creates the \Address directory if it doesn't exist, and suppress the message that appears when you create a new directory, add the /i command-line option as follows
xcopy \customer h:\public\address /s /e /k /p /iIdentify/sCopies directories and subdirectories, unless they're empty. Windows commands reference/eCopies all subdirectories, even if they're empty. Windows commands reference/kCopies files and retains the read-only attribute on _destination_ files if present on the _source_ files. Windows commands reference/pPrompts you to confirm whether you want to create each destination file. Windows commands reference/iIf _source_ is a directory or contains wildcards and _destination_ doesn't exist, xcopy assumes _destination_ specifies a directory name and creates a new directory. Windows commands reference8. You can create a batch program to perform xcopy operations and use the batch if command to process the exit code if an error occurs. For example, the following batch program uses replaceable parameters for the xcopy source and destination parameters
@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
:exitIdentifyTo use the preceding batch program to copy all files in the C:\Prgmcode directory and its subdirectories to drive B, type
copyit c:\prgmcode b:9. This example copies all the non-empty directories, plus files with the associated file extension after the asterisk symbol.
xcopy .\toc*.yml ..\..\Copy-To\ /S /Y
rem Output example.
rem .\d1\toc.yml
rem .\d1\d12\toc.yml
rem .\d2\toc.yml
rem 3 File(s) copiedIdentify/SCopies directories and subdirectories, unless they're empty. Windows commands reference/YSuppresses prompting to confirm that you want to overwrite an existing destination file. Windows commands referenceShow 34 options
<Source>Required. Specifies the location and names of the files you want to copy. This parameter must include either a drive or a path.[<Destination>]Specifies the destination of the files you want to copy. This parameter can include a drive letter and colon, a directory name, a file name, or a combination of these./wDisplays the following message and waits for your response before starting to copy files:
Press any key to begin copying file(s)/pPrompts you to confirm whether you want to create each destination file./cIgnores errors./vVerifies each file as it is written to the destination file to make sure that the destination files are identical to the source files./qSuppresses the display of xcopy messages./fDisplays source and destination file names while copying./lGenerates a list of files that are to be copied, but doesn't actively copy the files./gCreates decrypted _destination_ files when the destination doesn't support encryption./d [:MM-DD-YYYY]Copies source files changed on or after the specified date only. If you don't include a MM-DD-YYYY value, xcopy copies all _source_ files that are newer than existing _destination_ files. This command-line option allows you to update files that have changed./uCopies files from _source_ that exist on _destination_ only./iIf _source_ is a directory or contains wildcards and _destination_ doesn't exist, xcopy assumes _destination_ specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether _destination_ is a file or a directory./sCopies directories and subdirectories, unless they're empty. If you omit /s, xcopy works within a single directory./eCopies all subdirectories, even if they're empty. Use /e with the /s and /t command-line options./tCopies the subdirectory structure (that is, the tree) only, not files. To copy empty directories, you must include the /e command-line option./kCopies files and retains the read-only attribute on _destination_ files if present on the _source_ files. By default, xcopy removes the read-only attribute./rCopies read-only files./hCopies files with hidden and system file attributes. By default, xcopy doesn't copy hidden or system files/aCopies only _source_ files that have their archive file attributes set. /a doesn't modify the archive file attribute of the source file. For information about how to set the archive file attribute by using attrib, see Related links./mCopies _source_ files that have their archive file attributes set. Unlike /a, /m turns off archive file attributes in the files that are specified in the source. For information about how to set the archive file attribute by using attrib, see Related links./nCreates copies by using the NTFS short file or directory names. /n is required when you copy files or directories from an NTFS volume to a FAT volume or when the FAT file system naming convention (that is, 8.3 characters) is required on the _destination_ file system. The _destination_ file system can be FAT or NTFS./oCopies file ownership and discretionary access control list (DACL) information./xCopies file audit settings and system access control list (SACL) information (implies /o)./exclude:FileName1[+[FileName2]]+[FileName3]Specifies a list of files. At least one file must be specified. Each file contains search strings with each string on a separate line in the file. When any of the strings match any part of the absolute path of the file to be copied, that file is excluded from being copied. For example, specifying the string obj will exclude all files underneath the directory obj or all files with the .obj extension./ySuppresses prompting to confirm that you want to overwrite an existing destination file./-yPrompts to confirm that you want to overwrite an existing destination file./zCopies over a network in restartable mode./bCopies the symbolic link instead of the files. This parameter was introduced in Windows Vista®./jCopies files without buffering. Recommended for very large files. This parameter was added in Windows Server 2008 R2./compressRequest network compression during file transfer where applicable./[-]sparseEnables or disables retaining the sparse state of files during copy process. If both parameters are specified, /-sparse overrides /sparse./nocloneDoesn't attempt block cloning as an optimization./?Displays help at the command prompt.Windows
Copy files and directory trees.
Copy the file(s) to the specified destination
xcopy path\to\file_or_directory path\to\destination_directoryIdentifyList files that will be copied before copying
xcopy path\to\file_or_directory path\to\destination_directory /pIdentify/pPrompts you to confirm whether you want to create each destination file. Windows commands referenceCopy the directory structure only, excluding files
xcopy path\to\file_or_directory path\to\destination_directory /tIdentify/tCopies the subdirectory structure (that is, the tree) only, not files. Windows commands referenceInclude empty directories when copying
xcopy path\to\file_or_directory path\to\destination_directory /eIdentify/eCopies all subdirectories, even if they're empty. Windows commands referenceKeep the source ACL in the destination
xcopy path\to\file_or_directory path\to\destination_directory /oIdentify/oCopies file ownership and discretionary access control list (DACL) information. Windows commands referenceAllow resuming when network connection is lost
xcopy path\to\file_or_directory path\to\destination_directory /zIdentify/zCopies over a network in restartable mode. Windows commands referenceDisable the prompt when the file exists in the destination
xcopy path\to\file_or_directory path\to\destination_directory /yIdentify/ySuppresses prompting to confirm that you want to overwrite an existing destination file. Windows commands reference