xcopy (2024)

  • Article

Copies files and directories, including subdirectories.

For examples of how to use this command, see Examples.

Syntax

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]

Parameters

ParameterDescription
<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 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.
/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.
/?Displays help at the command prompt.
/sparseEnables retaining the sparse state of files during copy.

Remarks

  • 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:

    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

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

  • Insufficient memory error

    An "insufficient memory" error may occur if running xcopy to copy a file or folder whose filename path is greater than 255 characters.

  • Exit codes for xcopy

    To process exit codes returned by xcopy, use the ErrorLevel parameter on the if command line in a batch program. For an example of a batch program that processes exit codes using if, see Related links. The following table lists each exit code and a description.

    Exit codeDescription
    0Files were copied without error.
    1No files were found to copy.
    2The user pressed CTRL+C to terminate xcopy.
    4Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
    5Disk write error occurred.

Examples

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

8. 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 offrem COPYIT.BAT transfers all files in all subdirectories ofrem the source drive or directory (%1) to the destinationrem drive or directory (%2)xcopy %1 %2 /s /eif errorlevel 4 goto lowmemoryif errorlevel 2 goto abortif errorlevel 0 goto exit:lowmemoryecho Insufficient memory to copy files orecho invalid drive or command-line syntax.goto exit:abortecho You pressed CTRL+C to end the copy operation.goto exit:exit

To 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:

The command interpreter substitutes C:\Prgmcode for %1 and B: for %2, then uses xcopy with the /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 appropriate IF ERRORLEVEL statement, then displays the appropriate message and exits from the batch program.

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 /Yrem Output example.rem .\d1\toc.ymlrem .\d1\d12\toc.ymlrem .\d2\toc.ymlrem 3 File(s) copied

In the preceding example, this particular source parameter value .\toc*.yml copies the same 3 files even if its two path characters .\ were removed. However, no files would be copied if the asterisk wildcard was removed from the source parameter, making it just .\toc.yml.

xcopy (2024)

FAQs

What is the limitation of Xcopy? ›

Limitations. XCOPY fails with an "insufficient memory" error when the path plus filename is longer than 254 characters.

Why is Xcopy not copying everything? ›

If you are not using XCOPY with administrator rights, you may lack permission to read the contents of some files. Therefore, XCOPY will be unable to copy the file due to a lack of permission to read the file's data. If you encounter this problem, you can use XCOPY with administrator rights.

Does Xcopy copy all files? ›

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

Why use Xcopy instead of copy? ›

XCOPY is a much more powerful copying command than the COPY command. It is especially useful when backing up your fixed disk. A common usage would be to use the /S option along with the /D:date option to back up only the files that have been changed since the date of your last backup.

Is xcopy reliable? ›

Personal File Management: If you need to manage individual files on a small scale, Xcopy is a reliable option. Copying files, directories, and subdirectories simplifies the process and makes it an ideal solution for backups, transferring files within a small network, and organising personal files.

Did Robocopy replace xcopy? ›

Starting with the definitions, the "copy" command is used for copying files or data, and "Xcopy" is used to copy multiple files or complete directory trees from one directory to another, etc. Finally, "Robocopy" replaces "Xcopy" with various options.

Is xcopy faster? ›

The average Disk Average Write Request Time is better for Robocopy (0.51 ms. vs. 0.52 ms.), the minimum Disk Average Write Request Time is better for XCopy (0.00 ms.

What is the alternative of xcopy in Windows? ›

It is a wise move to choose Xcopy alternative when you facing Xcopy not working or fails to copy files issue. AOMEI Backupper is able to copy files from one location to another in another way. For Windows Server Operating Systems users, AOMEI Backupper Server is of much more help.

How do I force xcopy to copy a file? ›

Use the /i option to force xcopy to assume that destination is a directory. If you don't use this option, and you're copying from source that is a directory or group of files and copying to destination that doesn't exist, the xcopy command will prompt you enter whether destination is a file or directory.

Does xcopy copy hidden files? ›

Hi, 'Xcopy' is the only command that will allow you to copy hidden files. There are no other commands that will help you accomplish the same.

Can xcopy clone a hard drive? ›

You can also use the Xcopy command to clone a hard drive. Xcopy is a program designed to copy files and directories (including subdirectories) from one location to another.

Why is xcopy so slow? ›

The symptom tends to occur when the source data for XCOPY requests is highly fragmented. The issue may depend on historical data usage or other environmental factors. Under such conditions, internal XCOPY flush processes typically become loaded and slow.

Why is Robocopy better than just copy? ›

I use it because it does many things that normal copy can't. It has many switches, here are some of the things I use it for: copy just files that have changed or are new since the last copy. sync one directory to the other, deleting anything that is not in the source directory.

How reliable is Robocopy? ›

Reliable. If Robocopy encounters an error, it will try again multiple times. Speed. It's faster than the standard copy function, especially for lots of files.

Which is better, xcopy or Robocopy? ›

Robocopy is used to mirror or sync directories while Xcopy does nothing about that. Robocopy can check the destination directory and delete all the files no longer in the main tree rather than copy all the files from one directory to another. In addition, it won't copy the unchanged files to save your time.

What is the limitation of Robocopy? ›

Limitations. Robocopy does not copy open files. Any process may open files for exclusive read access by withholding the FILE_SHARE_READ flag during opening. Normally Volume Shadow Copy Service is used for such situations, but Robocopy does not use it.

Does xcopy retain permissions? ›

To preserve permissions when files and folders are copied or moved, use the Xcopy.exe utility with the /O or the /X switch. The object's original permissions will be added to inheritable permissions in the new location.

Top Articles
Best Budgeting Apps For 2024
115 Real Estate Infographics - Use To Ignite Your Content Marketing [Updated]
Navicent Human Resources Phone Number
AllHere, praised for creating LAUSD’s $6M AI chatbot, files for bankruptcy
Pet For Sale Craigslist
Chelsea player who left on a free is now worth more than Palmer & Caicedo
Directions To 401 East Chestnut Street Louisville Kentucky
GAY (and stinky) DOGS [scat] by Entomb
Cinepacks.store
Music Archives | Hotel Grand Bach - Hotel GrandBach
270 West Michigan residents receive expert driver’s license restoration advice at last major Road to Restoration Clinic of the year
Natureza e Qualidade de Produtos - Gestão da Qualidade
Sitcoms Online Message Board
7440 Dean Martin Dr Suite 204 Directions
charleston cars & trucks - by owner - craigslist
Craigslist Farm And Garden Tallahassee Florida
Money blog: Domino's withdraws popular dips; 'we got our dream £30k kitchen for £1,000'
Colorado mayor, police respond to Trump's claims that Venezuelan gang is 'taking over'
Vermont Craigs List
Video shows two planes collide while taxiing at airport | CNN
Itziar Atienza Bikini
Craigslist Mt Pleasant Sc
Publix Super Market At Rainbow Square Shopping Center Dunnellon Photos
How Long After Dayquil Can I Take Benadryl
What Are The Symptoms Of A Bad Solenoid Pack E4od?
Happy Homebodies Breakup
Prot Pally Wrath Pre Patch
Fleet Farm Brainerd Mn Hours
Divina Rapsing
Roanoke Skipthegames Com
January 8 Jesus Calling
Culver's.comsummerofsmiles
Speechwire Login
Spirited Showtimes Near Marcus Twin Creek Cinema
James Ingram | Biography, Songs, Hits, & Cause of Death
Citibank Branch Locations In Orlando Florida
Craigslist Gigs Norfolk
6143 N Fresno St
Panchitos Harlingen Tx
THE 10 BEST Yoga Retreats in Konstanz for September 2024
Kgirls Seattle
Plead Irksomely Crossword
Spn-523318
Craigslist Free Manhattan
Silive Obituary
Ehome America Coupon Code
Senior Houses For Sale Near Me
Gary Vandenheuvel Net Worth
Lawrence E. Moon Funeral Home | Flint, Michigan
The Pretty Kitty Tanglewood
Goosetown Communications Guilford Ct
91 East Freeway Accident Today 2022
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 6567

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.