The Wild World of XCopy Content from the guide to life, the universe and everything

The Wild World of XCopy

1 Conversation

XCOPY is a program available with most Windows versions, and newer versions of DOS. It is normally found in the command subdirectory of Windows or in your DOS directory, named XCOPY.EXE.

By running XCopy, you can copy lots of files much more quickly than you normally could using Windows1 or even the COPY command, and you can decide to only copy the files you want.

Copying files is very useful: If you want two copies of something, for example you want to put something on a floppy disk or create a back-up copy in case you accidentally ruin your document, or just want to copy something because you can.

When To Use XCopy

Use XCopy any time you want to copy a large number of files - especially if you want to copy files modified after a certain date; or want to be asked before copying each file, which would take a long time in Windows.

The reason it copies files much more quickly than Windows is that it doesn't bother displaying a nice bar telling you how far you've got, and doesn't try to provide an amount of time until it is completed. It works on the principle that if you said you wanted to copy those files, you will still want to copy them however long it takes.

How To Use XCopy

By typing,

XCOPY "Source (File To Copy)" "Destination (Where To Copy To)"
into your MS-DOS prompt2 or Windows Run dialogue box (in the Start Menu), you can copy a file (or files, using wildcards as described below) from one place to another. You only need the quotes if there are spaces in the file names.

You will normally need to specify the full path3 of the file(s), using backslashes (\) and not forward slashes (/).

XCopy will only copy files within your computer. For example, you cannot copy a file from an Internet site using XCopy.

Wildcards

You can copy all the files with certain names by using wildcards. In place of a character, you can use a question mark (?). For example, to copy "c:\my documents\New Word Document.doc", you could type

XCOPY "c:\my documents\New?W?rd Docume?t.d??" "a:\"
This will copy the file, along with other documents to which it could refer, such as "c:\my documents\New Ward Document.dat"

You can use an asterisk or star (*) in place of any number of characters (including none at all):

XCOPY "c:\my documents\*W*D?cument.*" "a:\"
Use *.* or * to copy all files. To copy all word documents, use *.doc (eg: xcopy "c:\my documents\*.doc" "a:\")

When copying several files, note that it will only copy from the one directory you specify. To copy files in folders which are 'inside' the folder you are copying from, you will need to specify the /S option. See 'Parameters and Copying files' in 'Subdirectories' (below).

Missing designations

It is possible to use XCopy without specifying a destination (a place to copy to). If you do that from the MS-DOS prompt, it will copy the files to your current directory (the directory before the > sign). If you do that in Windows, you never quite know where it will end up.

This is the same result as putting a full stop or period (.) - which represents the current directory - in the destination, and is only really useful in MS-DOS.

Bizarrely, you can copy files to nowhere: by typing NUL as the destination, without quotes, XCopy will copy the whole thing... nowhere4.

Syntax

According to the help file, the full, horrid syntax of XCOPY is:

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/W] [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U] [/K] [/N]

Stopping XCopy

Press Ctrl+Pause/Break or Ctrl+C to stop. If you are running in a window, you will be able to close the window normally to achieve the same result.

Parameters

XCOPY has several parameters (options) which allow you to copy only the files you want. You should place parameters at the end of the XCOPY statement.

For example, including the /D and /M parameters (see below for what these do):

XCOPY "c:\my documents\New Word Document.doc" "a:\" /D /M

Date

  • /D:date - Copies files modified after the date specified. The date must be in the format dd.mm.yy, eg: /D:31.12.99
  • /D - Copies files to overwrite older files, but keeps newer ones.

Copying Files In Subdirectories

Subdirectories are the file folders which are 'inside' the folder you are copying from. For example, if you are copying files from My Documents, XCopy can copy files in all the folders inside My Documents, and all the folders inside them, and so on.

You could copy a whole drive by saying that you want to copy all the files in your root directory (the lowest level) and all its subdirectories.

XCOPY "c:\" "a:\" /S

  • /S - Copies files and also those in subdirectories. This will also create those folders. It will not copy empty folders which do not have any files to be copied in them.
  • /E - Use this instead of or as well as /S to copy files in subdirectories, plus any empty subdirectories.
  • /T - Creates the subdirectories (folders) used, but does not copy any files. (This creates the directory structure)
  • /T /E - Creates the subdirectories (folders) including empty subdirectories, but does not copy any files.

Asking You

  • /P - Prompts (asks) before copying each file.
  • /W - Waits for you to press a key before starting, saying:
    Press any key to begin copying file(s)

Display

  • /Q - Does not display file names while copying (makes it quiet). This option could unnerve you, as you never know what it's doing.
  • /F - Displays full source and destination file names while copying.

Don't copy anything

By using /L, you can display the names of the files you want to copy, to check you are copying only the files you want to.

  • /L - Just display the names of the files to copy, without actually copying them. (lists files to copy)

Copying Hidden & Read-Only Files

  • /H - Also copies hidden and system files.
  • /R - Overwrites read-only files.
  • /K - Copies the attributes on files. The read-only attribute will normally be turned off on the copy of the file.

Update Files

  • /U - Updates the files that already exist, while not copying any files that don't exist.

Making sure

Verifying will slow down copying, but will make absolutely sure files are copied correctly. It is usually unnecessary. This is the same as specifying VERIFY ON5 at the DOS-Prompt (see if you have verify on by typing VERIFY and turn off using VERIFY OFF).

  • /V - Verifies the file has been copied correctly.

Archive

The archive attribute applies to all files, and is used by programs to signify when it has been backed up, and when it has been changed. When you modify a file, the archive attribute is turned on. When you back up a file, your backup software may turn the attribute off. XCopy can turn off the archive attribute, and can be set to only copy modified files.

  • /A - Copies files with the archive attribute on (ie: modified files)
  • /M - Copies files with the archive attribute on, then turns it off, signifying that it has been backed up. (Modifies the archive attribute)

You cannot use /A and /M together. To use one of these parameters, type it (after a space) at the end of the XCOPY statement.

Assumptions

  • /I (/i) - If destination does not exist and you are copying more than one file, assumes that destination must be a directory. Otherwise it will ask you. It is a good idea to say it is a directory, as otherwise it will copy all the data from the files to one large file. If you don't specify this parameter, you will be asked if it refers to a file or directory.

Overwrite

  • /Y - Overwrites existing files without prompting.
  • /-Y - Prompts before overwriting existing files. This is the default option, and is only required to override /Y when placed in the COPYCMD environment variable6.
  • /R - Overwrites read-only files.

Online Help

Type:

XCOPY /?
for the help file. Or
XCOPY /? > PRN
to print it, or even
XCOPY /? > "C:\WINDOWS\DEKSTOP\XCOPY HELP FILE.TXT"
to copy it to a file on your desktop.

Errors

  • /C - Use this parameter to continue copying despite errors.
  • File Not found FileName - The file does not exist. You may have misspelled it or you may be in the wrong directory. Use the full path* with files to make sure you copy the right file.
  • Invalid number of parameters - You didn't put in a source, or put something after the destination.
  • Bad command or File name You don't have XCOPY.

XCopy and Its Friends

XCOPY is very useful, but is not always the best thing to use in all situations. It has many friends, as outlined below.

  • If you're copying an entire disk, you should use DISKCOPY, like this:
    DISKCOPY drive letter to copy from:drive letter to copy to:
    eg: DISKCOPY a: a: or: DISKCOPY a: b: (for 2 floppy drives)
    this has some parameters which you can use like the XCOPY parameters:
    • /1 copy the first side of the disk only. There is no real reason to use this because you normally want all the data from the disk.
    • /V verifies information in exactly the same way as XCOPY does (see above)
    • /M uses your memory only, which means it won't use your hard drive when copying, but you will have to keep switching the disks over, as less data is copied in one go.
    The two disks must be of the same type (eg, both 3.5 in floppy disks)

    If you want to copy only certain files between two floppy disks but only have one floppy drive, you can do so with ordinary copy or XCopy. You can use the phantom floppy drive, b:. Simply call one disk drive a:, as normal, and the other you can prtend is in a different floppy drive, b: (eg: COPY a:\wow!.txt b:\). Copying directly between two floppy disks means that you have to keep switching the disks over (as you only have one floppy drive instead of two), just like DISKCOPY /M. It's normally much better to copy them to the hard drive somewhere*, than onto the second floppy disk.
  • COPY is the origional version of XCOPY. It can copy lots of files with similar names using wildcards (COPY file(s)_to_copyplace_to_copy_to). It is more limited in what it can do than XCOPY, and its only special feature is that you can use COPY to stick lots of files together into one big file.
    To stick files together, use pluses (+) between them:
    COPY file1 + file2 + file3 end_file
    You should specify /A (ASCII Text) or /B (binary) after each source file to say what type of file it is.
    COPY also uses the /V and /Y or /-Y used in XCOPY.
  • Use MOVE to move files (this can have the parameter /Y or /-Y, just like XCOPY, see above). Move one or lots of files by
    MOVE file_to_move directory_to_move_files_to
    MOVE file1, file2, file3 directory_to_move_files_to
    You can use wildcards (see above).
  • Use REN (or RENAME) rename files within the same directory. You can use wildcards (see above).
  • To display a list of files use DIR. DIR has lots of parameters, type DIR /? for a full list.

XCopy use in DOS

MS-DOS Support

Some MS-DOS programs require files in the old 8.3 short-name format. XCopy can create files in 8.3 format (max eight-character name, plus a max. Three-character extension, eg: FILENAME.EXT) using the /N parameter. The MS-DOS names are generated by removing spaces and using the first 6 letters, then sticking ~1, ~2, ~3, etc. on the end. The MS-DOS name is shown in the file properties box (Windows) and the DIR command (supporting versions of dos)
  • /N Copy using the generated short names.

DOSKey

If you have DOSKey and use MS-DOS a lot, you can use XCopy instead of Copy automatically by using DOSKey Macros. Type
DOSKEY /INSERT
DOSKEY COPY=XCOPY $*
at the DOS Prompt. You can also use this to specify options, eg:
DOSKEY COPY=XCOPY $* /-Y /H /D
DOSKey is a really useful program for MS-DOS, allowing you to scroll through and edit previous commands. Type DOSKEY /? or HELP DOSKEY (depending on your DOS version) for help.

MS-DOS Batch

As with any MS-DOS prompt command, XCopy can be included in an MS-DOS batch file (.bat). To create a new MS-DOS Batch file, create a new text document, type in a list of commands you want to run (each on a separate line), and re-naming it with the .BAT extension. Run them at any time by double-clicking on them or typing their name (include path) at the DOS Prompt.
1To copy files in Windows, hold down Ctrl while dragging a file2You can open an MS-DOS prompt from your start menu (usually start - programs - MS-DOS Prompt), your Windows folder, or by typing COMMAND /K into the run dialogue box. Alternatively, your computer may start in MS-DOS. To quit DOS, type EXIT and press enter. To exit from MS-DOS mode, type EXIT (to restart Windows if applicable, or exit any MS-DOS TSR programs); then, if Windows doesn't start, restart or turn off your computer.3The path is the folder in which the file is stored. The path is shown on file properties box as the location. For example, if the location is "c:\my documents" and the file name is "nice.doc", the filename with full path is "c:\my documents\nice.doc"4You can copy it all to the screen by typing CON (for console) instead of NUL5To start verifying in the Run dialogue box, type COMMAND /C VERIFY ON6To set the COPYCMD environment variable to /Y, type SET COPYCMD=/Y at the DOS prompt or COMMAND /C SET COPYCMD=/Y at the run dialog box. This will apply until you turn off or reset your computer. To always use this, insert the command SET COPYCMD=/Y into your AUTOEXEC.BAT file. Please read your system documentation about your Autoexec.bat file before doing this.

Bookmark on your Personal Space


Edited Entry

A2054620

Infinite Improbability Drive

Infinite Improbability Drive

Read a random Edited Entry

Categorised In:


Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more