Xcopy command

Updated: 11/12/2023 by Computer Hope
xcopy command

Xcopy is a more robust version of the copy command with additional features. It can move files, directories, and drives from one location to another.

Tip

Users running recent versions of Windows should consider using robocopy instead of xcopy.

Availability

Xcopy is an external command available for the following Microsoft operating systems as xcopy.exe.

Xcopy syntax

Windows 10 and 11 syntax and switches

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U] [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B] [/J] [/EXCLUDE:file1[+file2][+file3]...] [/COMPRESS]
source Specifies the source of the file(s) to copy.
destination Specifies the destination location or name of the new files.
/A Copies only files with the archive attribute set; it doesn't change the attribute.
/M Copies only files with the archive attribute set, turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
/EXCLUDE:file1 [+file2][+file3]... Specifies a list of files containing strings. When any of the strings match any part of the absolute file path to be copied, that file is excluded from being copied. For example, specifying a string like \obj\ or .obj excludes all files underneath the directory obj or all files with the .obj extension, respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except for empty ones.
/E Copies directories and subdirectories, including empty ones. Same as /S /E. It can modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If the destination does not exist and copies more than one file, it assumes that the destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/G Allows the copying of encrypted files to a destination that does not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories.
/U Copies only files that already exist in the destination.
/K Copies attributes. Normal xcopy resets read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite an existing destination file.
/Z Copies networked files in restartable mode.
/B Copies the symbolic link itself versus the target of the link.
/J Copies using unbuffered I/O. We recommend for large files.
/COMPRESS Request network compression during file transfer, where applicable.

The switch /Y may be preset in the COPYCMD environment variable. This switch may be overridden with /-Y on the command line.

Windows 2000, XP, Vista, 7, and 8 syntax and switches

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U] [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B] [/J] [/EXCLUDE:file1[+file2][+file3]...]
Note

Only Windows Vista and later includes the [/B] and [/J] options.

source Specifies the source of the file(s) to copy.
destination Specifies the destination location or name of the new files.
/A Copies only files with the archive attribute set; it doesn't change the attribute.
/M Copies only files with the archive attribute set, turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
/EXCLUDE:file1 [+file2][+file3]... Specifies a list of files containing strings. When any of the strings match any part of the absolute file path to be copied, that file is excluded from being copied. For example, specifying a string like \obj\ or .obj excludes all files underneath the directory obj or all files with the .obj extension, respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except for empty ones.
/E Copies directories and subdirectories, including empty ones. Same as /S /E. It can modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If the destination does not exist and copying more than one file, it assumes that the destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories.
/U Copies only files that already exist in the destination.
/K Copies attributes. Normal xcopy resets read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite an existing destination file.
/Z Copies networked files in restartable mode.
/B Copies the symbolic link itself versus the target of the link.
/J Copies using unbuffered I/O. We recommend it for large files.

The switch /Y may be preset in the COPYCMD environment variable that can be overridden with /-Y on the command line.

Windows 98 and older syntax and switches

Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/W] [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U] [/K] [/N]
source Specifies the file(s) to copy.
destination Specifies the location or name of new files.
/A Copies files with the archive attribute set doesn't change the attribute.
/M Copies files with the archive attribute set turns off the archive attribute.
/D:date Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones. Same as /S /E. It can modify /T.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If the destination does not exist and copying more than one file, it assumes that the destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories.
/U Updates the files that already exist in the destination.
/K Copies attributes. Normal xcopy resets read-only attributes.
/Y Overwrites existing files without prompting.
/-Y Prompts you before overwriting existing files.
/N Copy using the generated short names.

Xcopy examples

xcopy *.* /h hope

In the example above, the xcopy command copies all the files (including hidden ones) in the current directory into the hope directory.

xcopy c:\temp /e

In the example above, is the basic xcopy command to copy the files, directories, and subdirectories in the temp directory to the current directory.

xcopy "c:\documents and settings\hope" /e

In the example above, the xcopy command would copy all files and directories in the user "hope" directory to the current directory.

xcopy hope example /e

In the example above, the xcopy command copies all directories (even empty directories) and files from the hope directory into the example directory.

xcopy h:\*.* /a /e /k

The command above copies everything on the H drive to the current directory.

Xcopy questions and answers

Getting Invalid number of parameters error

This error occurs when the command you're entering has spaces in it. When typing a directory with spaces in MS-DOS, make sure to surround the path with quotes. For example, instead of typing: c:\documents and settings type "c:\documents and settings" at the prompt.

Cannot perform a cyclic copy

This error occurs when you're trying to copy directories that contain the destination directory. If this command were to be allowed, it would get into a loop and would never stop copying. When using the xcopy command, if you copy all directories and subdirectories, the destination must be a completely separate directory or drive.

Parse error

This error occurs when the command you're typing in has invalid syntax. For example, if you're surrounding your path in quotes, leave out the ending quotes.

I attempted to use the above xcopy command and was not able to copy all files within my favorites folder

After further examination, Computer Hope also encountered this issue. However, we could copy most of all favorites using the command below. Also, consider using robocopy.

xcopy c:\windows\favorites\*.* /e /k /i /c

We are under the impression this issue is generated because of the way that Internet Explorer saves the URL (favorite) using long file names with extended characters.

What is xcopy32?

Xcopy32 was a command available with Microsoft Windows 95 and Windows 98. Although it can be run by itself, it is executed automatically when xcopy is used on a 32-bit file system like FAT32. For early 16-bit file systems that had both xcopy and xcopy32, the xcopy command is used. If you're trying to decide to run xcopy or xcopy32, always use xcopy.