XCOPY – Windows CMD Command


Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Copy files and/or directory trees to another folder. XCOPY is similar to the COPY command except that it has additional switches to specify both the source and destination in detail.

While still included in Windows 10, Xcopy has been deprecated in favor of Robocopy, a more powerful copy tool, which is now built into Windows Server and Desktop operating systems.

XCOPY will accept UNC pathnames.

To always overwrite destination files use the COPYCMD environment variable: SET COPYCMD=/Y

When comparing Dates/Times the granularity (the finest increment of the timestamp) is 2 seconds for a FAT volume and 0.1 microsecond for an NTFS volume.

Copy a single file

In most cases copying a single file is best done with the COPY command. When copying a single file with XCOPY, there is no option to indicate if the destination is a filename or a directory (with the filename defaulting to that of the source file).
In such cases XCOPY will prompt with a (locale specific) message like:
C:\> xcopy foo.txt bar.txt
Does foo.txt specify a file name
or directory name on the target
(F = file, D = directory)?

Adding a wildcard (*) to the end of the destination will suppress this prompt and default to copying as a file:
C:\> xcopy foo.txt bar.txt*
C:foo.txt
1 File(s) copied
This requires the source and target file extensions to be the same length, typically 3 characters.

Insufficient Memory error

Attempting to XCOPY a source file that has a pathname longer than the Windows maximum path length (254 characters) will result in a rather unhelpful ‘Insufficient Memory’ error, the operation will then halt. This bug which has been around for over 10 years makes XCOPY a poor choice for any kind of backup script, use ROBOCOPY instead.

Exit Codes

0 Files were copied without error.

1 No files were found to copy.

2 The user pressed CTRL+C to terminate xcopy.

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

5 Disk write error occurred.

Examples:

Copy a file:

echo F| XCOPY C:\utils\MyFile.txt D:\Backup\CopyFile.txt

Copy a folder:

XCOPY C:\utils D:\Backup\utils /i

Copy a folder including all subfolders.

XCOPY C:\utils\* D:\Backup\utils /s /i

You may also like...

4 Responses

  1. game nfts says:

    Hey would you mind letting me know which web host you’re utilizing?
    I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a lot quicker then most.
    Can you suggest a good hosting provider at a honest price?
    Kudos, I appreciate it!

  2. zoritoler imol says:

    It’s really a great and useful piece of info. I’m glad that you shared this useful information with us. Please keep us up to date like this. Thanks for sharing.

  3. zortilo nrel says:

    I would like to thnkx for the efforts you have put in writing this blog. I am hoping the same high-grade blog post from you in the upcoming as well. In fact your creative writing abilities has inspired me to get my own blog now. Really the blogging is spreading its wings quickly. Your write up is a good example of it.

  4. frolep rotrem says:

    I genuinely enjoy examining on this website , it has fantastic articles.

Leave a Reply

Your email address will not be published. Required fields are marked *