[ Back to Table of Contents ]
[ << ]
[ >> ]
XXCOPY TECHNICAL BULLETIN #25
From: Kan Yabumoto firstname.lastname@example.org
To: XXCOPY user
Subject: XXCOPY Command Line Syntax
Date: 2002-05-07 (revised)
Basic Command Parameter Syntax:
XXCOPY source destination (simplified syntax)
In its simplest form, XXCOPY takes two parameters,
from WHERE to WHERE
This very intuitive command syntax has its root in the COPY command
introduced in 1981 as a PC-DOS (MS-DOS) built-in command.
The first parameter is the source specifier and the second one is
the destination specifier. These two parameters must be in this
order. As common to the COPY and XCOPY command syntax, the
destination specifier can be omitted. Then, by default, the
current directory in the current drive becomes the destination.
XXCOPY source [ destination ]
By convention, an optional parameter is denoted in the syntax
definition with a pair of square-brackets surrounding it.
In addition, you may add command switches that starts with a
slash (see below).
The Command Line Delimiter:
XXCOPY source [ destination ] [ switches... ]
These up to three (or more) parts must be separated by at least one
blank (usually the space character but a tab may be used). The role
of the blank character as a separator (which is called "delimiter")
in the command line is very important. XXCOPY relies on the
separating blank characters to know where the end of the source
specifier and where is the beginning of the destination specifier.
For this reason, if you have a source specifier (such as "My Documents")
which has a space inside, you must enclose the whole source specifier
by double quotes.
XXCOPY "C:\My Documents\"
If you omit the double quotes, like the following line,
XXCOPY C:\My Documents
XXCOPY would interpret "C:\My" as the source specifier and "Documents"
as the destination (If you have another item which you really meant
as your destination, it would be ignored as a third and useless item).
It does not hurt to surround the source (or destination) specifier by
Full Command Parameter Syntax:
XXCOPY source [ destination ] [ switches... ]
All switches start with a slash (/) character whereas the source
and the destination specifiers do not have the slash(/) prefix.
The source and the destination specifiers must be separated from
other items in the command line by at least one blank (space or tab)
character. On the other hand, you may omit blank characters between
switches in order to minimize the total length of the command line.
XXCOPY C:\mydir\ D:\yourdir\ /S/H
Here, "C:\mydir\" is the source specifier and "D:\yourdir\" is
the destination specifier. They do not start with a slash (/).
It has two (/S and /H) switches.
Note that the positions of the switches need not be at the end
of the command line. Switches may begin even before the source
specifier. The following command line is equivalent to the one
XXCOPY /S C:\mydir\ /H D:\yourdir\
The order of the switches is not generally important except when
a conflicting switches are specified, the rightmost switch will
prevail. More rules for special cases are discussed at the end
of this article. For a complete syntax and semantics for the
source specifier, see XXTB #04.
Once you learn this simple rule, it is quite easy to understand a
long XXCOPY command line.
A command switch (we call it just switch most often) is any command
paremeter that is neither the source specifier (referred to as
"source" above) nor the destination specifier (referred to as
"destination" above). A switch instructs XXCOPY the details of
the operation which deviates the default behavior. As a matter of
fact, without the switches, XXCOPY is only as boring as the standard
XXCOPY c:\mydir\ d:\yourdir\
This line copies the files from one directory to another. Since
the default behavior is not to include hidden or system files, and
not to include subdirectories, this operation will copy just a handful
of regular files. If the destination already has some of the files
you will be greeted by a prompt asking whether you want to overwrite
the file or not. Moreover, if the existing file has the read-only
attribute (i.e., write-protected), you are out of luck.
The rich set of command switches set XXCOPY apart from other file
management tools. Being a command line program, XXCOPY is not
easy to use. You have no choice but to become familiar with the
very large collection of switches (over 175 switches and growing),
if you want to harness the power of XXCOPY. The good news is that
you need not learn all.
Syntactically, all of XXCOPY's command switches starts with a slash
( / some people call it forward-slash). To keep the command line
somewhat more manageable, XXCOPY allows you to connect one command
switch with the next without any delimiting character (typically
a space). With just one exception (XXTB #24), an item that starts
with a slash is a command switch.
For more discussion of XXCOPY command switches and the detailed
discussion of the source specifier, see the following
for Command Parameter Reference XXTB #01
for Command Reference Alphabetic Listing XXTB #26
for Command Reference Functional Classification XXTB #27
for The Wild-Wildcard Source Specifier XXTB #28
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Source Specifier (XCOPY-compatible standard):
XXCOPY's first argument (without regard to command switches) is
the source specifier. The source specifier is usually a path
specifier for the source. But, for Microsoft's XCOPY (and also for
our XXCOPY), the source specifier may contain the directory and
an optional file pattern specification whose subtleties are not
fully appreciated by many XXCOPY users.
The XCOPY-compatible source specifier has three parts:
[ volume_spec ] [ directory ] [ file_pattern ]
Example (the destination specifier is omitted here):
Here, the three parts in the XCOPY-compatible source specifier
are quite obvious. The second example is with the UNC which is
how you specify a remote drive (via a network).
In most cases, the volume spec is a drive letter followed by a
colon (e.g., C: ). But, it can be a universal naming convention
(UNC) string for a volume in a network (e.g., \\myserver\drivec ).
If you omit volume_spec, the current drive is assumed.
The name of the source directory. When the XXCOPY command
contains the subdirectory switch (/S and/or /E), the directory
specifier denotes the starting directory where the source
files and subdirectories are located. The XCOPY-comatible
directory part does not contain a wildcard character. The
more advanced "Wild-wild-source" feature in XXCOPY accepts
wildcards. For example,
XXCOPY C:\Windows\*\?cache*\*\*.jpg \dst\
A separate article, XXTB #28 gives you the full detail.
The last part within the source specifier denotes the pattern
matching string which may contain wildcard characters (* or ?).
It matches only the last components within a full filename.
Just to make the discussion of XXCOPY's command parameter syntax
complete, let us go over the subject of the remajing item, the
destination specifier. Fortunately the rules for this are not
complicated. The destination specifier has two parts:
[ volume_spec ] [ dest_dir ]
As for the source specifier case, the destination may contain
a volume specifier (e.g., C: ). If it is omitted, the volume
of the current directory will be used.
The name of the destination directory. Here, the destination
must be a directory name (which may or may not yet exist
in the destination volume). Unlike the original COPY command,
you are not allowed to specify wildcard characters in the
destination specifier which would be conveniently used to
perform renaming action while copying the files.
XXCOPY does not rename files while they are copied. therefore,
no wildcard characters have no place in dest_dir.
Unlike the source specifier counterpart, the destination specifier
consists of only two parts both of which are optional. When you
omit both of them, then the command line would have no explicit
argument as the destination specifier. Don't worry, the current
directory will be used as the default destination directory. Or,
you may just type "." which denotes the current directory explicitly.
The Base Directory:
When a directory (and the subdirectories) is copied from the
source to the destination, the first level of the source directory
will correspond to the first level of the destination directory
that is specified as the destination. We call the first level in
the source directory the "Base Directory". Since the destination's
first level directory is named by the destination specifier that
you provide in the command line, the directory name in the destination
is not always the same.
For example, when you run the following command,
XXCOPY c:\mypath\mysrcdir\ d:\your\dstdir\ /S
Any part of the Base Directory is not necessarily become a part
of the destination directory. This is true even the last name
(mysrcdir) does not automatically appear in the destination side.
The end result will be like this.
c:\mypath\mysrcdir\file1.doc --> d:\your\dstdir\file1.doc
c:\mypath\mysrcdir\sub1\a.doc --> d:\your\dstdir\sub1\a.doc
Here, the Base Directory is c:\mypath\mysrcdir\. The concept of
the Base Directory is even more important in the treatment of the
exclusion parameter. When an exclusion item is given as a relative
path, the directory path specified is relative to the Base Directory.
For example, with the same directory
XXCOPY c:\mypath\mysrcdir\ d:\your\dstdir\ /S /Xtemp*\
The exclusion switch's parameter (temp*\) is understood to be
relative to the Base Directory which is in this case:
Of course, you may always use an absolute path for the /X parameter:
XXCOPY c:\mypath\mysrcdir\ \dst\ /S /Xc:\mypath\mysrcdir\temp*\
A more rigorous definition of Base Directory will be given in the
discussion of the source directory which contain wildcards
(Wild-Wildcard Source) XXTB #28.
© Copyright 2014 Pixelab All rights reserved.