X copy is a powerful and versatile command to copy and backup files and directories. Syntax and usage of the Xcopy command.




Xcopy command syntax


The Xcopy command has a large number of possible options which makes it very powerful and flexible.


The syntax of the Xcopy command is as follows:



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]



Table I. Xcopy Options




Required. Specifies the location and names of the files you want to copy. This parameter must include either a drive or a path.


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.


Displays the following message and waits for your response before starting to copy files:

Press any key to begin copying file(s)


Prompts you to confirm whether you want to create each destination file.


Ignores errors.


Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files.


Suppresses the display of xcopy messages.


Displays source and destination file names while copying.


Displays a list of files that are to be copied.


Creates decrypted Destination files when the destination does not support encryption.

/d [:MM-DD-YYYY] 

Copies source files changed on or after the specified date only. If you do not 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. Copies files and directories, including subdirectories.


Copies files from Source that exist on Destination only.


If Source is a directory or contains wildcards and Destination does not 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.


Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory.


Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options.


Copies the subdirectory structure (that is, the tree) only, not files. To copy empty directories, you must include the /e command-line option.


Copies files and retains the read-only attribute on Destination files if present on the Source files. By default, xcopy removes the read-only attribute.


Copies read-only files.


Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.


Copies only Source files that have their archive file attributes set. /a does not modify the archive file attribute of the source file. 


Copies 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. 


Creates 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. 


Copies file ownership and discretionary access control list (DACL) information. 


Copies 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 will contain 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 will be 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.


Suppresses prompting to confirm that you want to overwrite an existing destination file.


Prompts to confirm that you want to overwrite an existing
destination file. 


Copies over a network in restartable mode. 


Copies the symbolic link instead of the files. This parameter was introduced in Windows Vista®.


Copies files without buffering. Recommended for very large files. This parameter was added in Windows Server 2008 R2.


Displays help at the command prompt.




  • 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 are prompted to overwrite.


  • Copying encrypted files

Copying encrypted files to a volume that does not 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 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)?


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 (See also attrib command).

The xcopy command creates files with the archive attribute set, whether or not this attribute was set in the source file.


  • 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 does not have this requirement. Use xcopy unless you need a complete disk image copy.


  • Exit codes for xcopy

To process exit codes returned by xcopy, use the ErrorLevel parameter on the if command line in a batch program.


The following table lists each exit code and a description.



Table II. Xcopy exit code

Exit Code



Files were copied without error.


No files were found to copy.


The user pressed CTRL+C to terminate xcopy.


Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.


Disk write error occurred.


CMD Windows




1. To copy all the files and subdirectories (including any empty subdirectories) from drive A to drive B, type:


xcopy a: b: /s /e


2. 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


3. 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-1993


4. To update all the files that exist in \reports in the previous example, regardless of date, type:


xcopy \rawdata \reports /u


5. 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.out


The file xcopy.out lists every file that is to be copied.


6. 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 /p


7. To issue the previous command, ensure that xcopy creates the \Address directory if it does not 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 /i