COPY - Copy files
Purpose: Copy data between disks, directories, files, or physical
hardware devices (such as your printer or serial port).
Format: COPY [/A:[[-]rhsda] /C /E /F /H /K /M /N /P /Q /R /S /T /U /V
/X /Z] source [+] ... [/A /B] destination [/A /B]
source : A file or list of files or a device to copy from .
destination : A file, directory, or device to copy to .
/A(SCII) /P(rompt)
/A: (Attribute select) /Q(uiet)
/B(inary) /R(eplace)
/C(hanged) /S(ubdirectories)
/E (no Error messages) /T(otals)
/F(ail on EA error) /U(update)
/H(idden) /V(erify)
/K(eep attributes) /X (clear archive)
/M(odified) /Z (overwrite)
/N(othing)
See also: ATTRIB, MOVE, and REN.
File Selection
Supports extended wildcards, ranges, multiple file names, and include
lists. Date, time, size, or exclude ranges anywhere on the line apply to
all source files.
Usage
The COPY command accepts all traditional syntax and options and adds many
new features.
The simplest use of COPY is to make a copy of a file, like this example
which makes a copy of a file called FILE1.ABC :
[c:\] copy file1.abc file2.def
You can also copy a file to another drive and/or directory. The
following command copies FILE1 to the \MYDIR directory on drive E:
[c:\] copy file1 e:\mydir
You can copy several files at once by using wildcards:
[c:\] copy *.txt e:\mydir
When you COPY files to or from an HPFS drive, you must quote the path
name if it contains whitespace or special characters. See File Names and
File Systems for additional details.
Copying Files
You can copy several files at once by using wildcards:
[c:\] copy *.txt e:\mydir
You can also list several source files in one command. The following
command copies 3 files from the current directory to the \MYDIR directory
on drive E:
[c:\] copy file1 file2 file3 e:\mydir
COPY also understands include lists, so you can specify several different
kinds of files in the same command. This command copies the .TXT, .DOC,
and .BAT files from the E:\MYDIR directory to the root directory of drive
A:
[c:\] copy e:\mydir\*.txt;*.doc;*.bat a:\
If there is only one argument on the line, COPY assumes it is the source,
and uses the current drive and directory as the destination. For
example, the following command copies all the .DAT files on drive A to
the current directory on drive C:
[c:\data] copy a:*.dat
If there are two or more arguments on the line, separated by spaces, then
COPY assumes that the last argument is the destination and copies all
source files to this new location. If the destination is a drive,
directory, or device name then the source files are copied individually
to the new location. If the destination is a file name, the first source
file is copied to the destination, and any additional source files are
then appended to the new destination file.
For example, the first of these commands copies the .DAT files from the
current directory on drive A individually to C:\MYDIR (which must already
exist as a directory); the second appends all the .DAT files together
into one large file called C:\DATA (assuming C:\DATA is not a directory):
[c:\] copy a:*.dat c:\mydir\
[c:\] copy a:*.dat c:\data
When you copy to a directory, if you add a backslash [\] to the end of
the name as shown in the first example above, COPY will display an error
message if the name does not refer to an existing directory. You can use
this feature to keep COPY from treating a mistyped destination directory
name as a file name and attempting to append all your source files to a
destination file, when you really meant to copy them individually to a
destination directory.
To copy a file to a device such as the printer, use the device name as
the destination, for example:
[c:\] copy schedule.txt prn
To copy text to or from the clipboard use CLIP: as the device name.
Using CLIP: with non-text data will produce unpredictable results. See
Redirection for additional information on CLIP:.
Appending Files
A plus [+] tells COPY to append two or more files to a single destination
file. If you list several source files separated with [+] and don't
specify a destination, COPY will use the name of the first source file as
the destination, and append each subsequent file to the first file.
For example, the following command will append the contents of C:\MEMO2
and C:\MEMO3 to C:\MEMO1 and leave the combined contents in the file
named C:\MEMO1 :
[c:\] copy memo1+memo2+memo3
To append the same three files but store the result in BIGMEMO:
[c:\] copy memo1+memo2+memo3 bigmemo
To append C:\MEM\MEMO2 and C:\MEM\MEMO3 to D:\DATA\MEMO1, and leave the
result in C:\MEM\MEMO1 : If no destination is specified, the destination
file will always be created in the current directory even if the first
source file is in another directory or on another drive. For example,
this command will append C:\MEM\MEMO2 and C:\MEM\MEMO3 to D:\DATA\MEMO1,
and leave the result in C:\MEM\MEMO1 :
[c:\mem] copy d:\data\memo1+memo2+memo3
You cannot append files to a device (such as a printer); if you try to do
so, COPY will ignore the [+] signs and copy the files individually. If
you attempt to append several source files to a destination directory or
disk, COPY will append the files and place the copy in the new location
with the same name as the first source file.
Advanced Features
If your destination has wildcards in it, COPY will attempt to match them
with the source names. For example, this command copies the .DAT files
from drive A to C:\MYDIR and gives the new copies the extension .DX :
[c:\] copy a:*.dat c:\mydir\*.dx
This feature can give you unexpected results if you use it with multiple
source file names. For example, suppose that drive A contains XYZ.DAT
and XYZ.TXT. The command
[c:\] copy a:\*.dat a:\*.txt c:\mydir\*.dx
will copy A:XYZ.DAT to C:\MYDIR\XYZ.DX. Then it will copy A:XYZ.TXT to
C:\MYDIR\XYZ.DX, overwriting the first file it copied.
COPY also understands include lists, so you can specify several different
kinds of files in the same command. This command copies the .TXT, .DOC,
and .BAT files from the E:\MYDIR directory to the root directory of drive
A:
[c:\] copy e:\mydir\*.txt;*.doc;*.bat a:\
You can use date, time, and size ranges to further define the files that
you want to copy. This example copies every file in the E:\MYDIR
directory, which was created or modified yesterday, and which is also
10,000 bytes or smaller in size, to the root directory of drive A:
[c:\] copy /[d-1] /[s0,10000] e:\mydir\*.* a:\
You can also use file exclusion ranges to restrict the list of files that
would normally be selected with wildcards. This example copies every
file in the E:\MYDIR directory except backup (.BAK or .BK!) files:
[c:\] copy /[!*.bak;*.bk!] e:\mydir\*.* a:\
COPY will normally process source files which do not have the hidden or
system attribute, and will ignore the read-only and archive attributes.
It will always set the archive attribute and clear the read-only
attribute of destination files. In addition, if the destination is an
existing file with the read-only attribute, COPY will generate an "Access
Denied" error and refuse to overwrite the file. You can alter some of
these behaviors with switches:
/A: Forces COPY to process source files with the attributes you
specify after the ":", or to process all source files
regardless of attributes (if /A: is used by itself).
/H Forces COPY to process hidden and system source files, as well
as normal files. The hidden and system attributes from each
source file will be preserved when creating the destination
files.
/K Retains the read-only attribute from each source file when
creating the destinationfile. See /K below for a special note
if you are running under Novell Netware.
/Z Forces COPY to overwrite an existing read-only destination
file.
Use caution with /A:, /H, or /K when both the source and destination
directories contain file descriptions. If the source file specification
matches the description file name (normally DESCRIPT.ION), and you use a
switch which tells COPY to process hidden files, the DESCRIPT.ION file
itself will be copied, overwriting any existing file descriptions in the
destination directory. For example, if the \DATA directory contains file
descriptions this command would overwrite any existing descriptions in
the \SAVE directory:
[c:\data] copy /h d*.* \save\
(If you remove the hidden attribute from the DESCRIPT.ION file the same
caution applies even if you do not use /A:, /H, or /K, as DESCRIPT.ION is
then treated like any other file.)
If you copy a file from a FAT volume to an HPFS volume, and you do not
give an explicit destination name (i.e. you are moving the file to the
current directory, or your destination name is made up entirely of
wildcards), COPY will look for a .LONGNAME extended attribute for the
source file. If it finds that attribute, it will use the long filename
for the destination file. If it does not, it will use the short name.
Similarly, if you COPY files with long filenames from an HPFS volume to a
FAT volume, CMD.EXE will create the destination files with short,
FAT-compatible names and save the long filenames in the .LONGNAME
extended attribute. The short name is created by replacing special
characters with underscores, adding numeric digits to the filename (if
necessary) to make the new name unique, and truncating the name to fit
with in the "8.3" FAT name structure.
Options
The /A(SCII) and /B(inary) options apply to the preceding filename and to
all subsequent filenames on the command line until the file name
preceding the next /A or /B, if any. The other options (/A:, /C, /E, /H,
/K, /M, /N, /P, /Q, /R, /S, /T, /U, /V, /X, /Z) apply to all filenames on
the command line, no matter where you put them. For example, either of
the following commands could be used to copy a font file to the printer
in binary mode:
[c:\] copy /b myfont.dat prn
[c:\] copy myfont.dat /b prn
Some options do not make sense in certain contexts, in which case COPY
will ignore them. For example, you cannot prompt before replacing an
existing file when the destination is a device such as the printer --
there's no such thing as an "existing file" on the printer. If you use
conflicting output options, like /Q and /P, COPY will generally take a
"conservative" approach and give priority to the option which generates
more prompts or more information.
/A: (ASCII) If you use /A with a source filename, the file will be
copied up to, but not including, the first Ctrl-Z (Control-Z
or ASCII 26) character in the file (some application programs
use the Ctrl-Z to mark the end of a file). If you use /A with
a destination filename, a Ctrl-Z will be added to the end of
the file. /A is the default when appending files, or when the
destination is a device like NUL or PRN, rather than a disk
file. Also see /B.
/A:: (Attribute select) Select only those files that have the
specified attribute(s) set. Preceding the attribute character
with a hyphen [-] will select files that do not have that
attribute set. The colon [:] after /A is required. The
attributes are:
R Read-only
H Hidden
S System
D Subdirectory
A Archive
If no attributes are listed at all (e.g., COPY /A: ...), COPY will select
all files and subdirectories including hidden and system files. If
attributes are combined, all the specified attributes must match for a
file to be selected. For example, /A:RHS will select only those files
with all three attributes set.
See the cautionary note under Advanced Features above before using /A:
when both source and destination directories contain file descriptions.
You must include the colon with this option to distinguish it from the
/A(SCII) switch, above. /B:(Binary) If you use /B with a source filename,
the entire file is copied; Ctrl-Z characters in the file do not affect
the copy operation. Using /B with a destination filename prevents
addition of a Ctrl-Z to the end of the destination file. /B is the
default for normal file copies. Also see /A. /C:(Changed files) Copy
files only if the destination file exists and is older than the source
(see also /U). This option is useful for updating the files in one
directory from those in another without copying any newly created files.
/E:(no Error messages) Suppress all non-fatal error messages, such as
"File not found." Fatal error messages, such as "Drive not ready," will
still be displayed. This option is most useful in batch files and
aliases. /F:(Fail on EA error) Fail if the source file has extended
attributes and the destination file system doesn't support extended
attributes. /H:(Hidden) Copy all matching files including those with the
hidden and/or system attribute set.
See the cautionary note under Advanced Features above before using /H
when both source and destination directories contain file descriptions.
/K:(Keep attributes) To maintain compatibility with CMD.EXE, COPY
normally maintains the hidden and system attributes, sets the archive
attribute, and removes the read-only attribute on the destination file.
/K tells COPY to also maintain the read-only attribute on the
destination file. However, if the destination is on a Novell Netware
volume, this option will fail to maintain the read-only attribute. This
is due to the way Netware handles file attributes, and is not a problem
in COPY. /M:(Modified) Copy only those files with the archive attribute
set, i.e., those which have been modified since the last backup. The
archive attribute of the source will not be cleared after copying; to
clear it use the /X switch, or use ATTRIB. /N:(Nothing) Do everything
except actually perform the copy. This option is useful for testing what
the result of a complex COPY command will be. /N does not prevent
creation of destination subdirectories when it is used with /s.
/P:(Prompt) Ask the user to confirm each source file. Your options at
the prompt are explained in detail under Page and File Prompts.
/Q:(Quiet) Don't display filenames or the total number of files copied.
This option is most often used in batch files. See also /T.
/R:(Replace) Prompt the user before overwriting an existing file. Your
options at the prompt are explained in detail under Page and File
Prompts. /S:(Subdirectories) Copy the subdirectory tree starting with the
files in the source directory plus each subdirectory below that. The
destination must be a directory; if it doesn't exist, COPY will attempt
to create it. COPY will also attempt to create needed subdirectories on
the tree below the destination, including empty source directories. If
COPY /S creates one or more destination directories, they will be added
automatically to the extended directory search database.
If you attempt to use COPY /S to copy a subdirectory tree into part of
itself, COPY will detect the resulting infinite loop, display an error
message, and exit. /T:(Totals) Turns off the display of filenames, like
/Q, but does display the total number of files copied. /U:(Update) Copy
each source file only if it is newer than a matching destination file or
if a matching destination file does not exist (see also /C). This option
is useful for keeping one directory matched with another with a minimum
of copying. /V:(Verify) Verify each disk write. This is the same as
executing the VERIFY ON command, but is only active during the COPY. /V
does not read back the file and compare its contents with what was
written; it only verifies that the data written to disk is physically
readable. /X:Clears the archive attribute from the source file after a
successful copy. This option is most useful if you are using COPY to
maintain a set of backup files. /Z:Overwrites read-only destination
files. Without this option, COPY will fail with an "Access denied" error
if the destination file has its read-only attribute set. This option
allows COPY to overwrite read-only files without generating any errors.
Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs