|Purpose:||Copy data between disks, directories, files, or physical hardware devices (such as your printer or serial port)|
|Format:||COPY [/= /I"text"] [/A:... /C /CF /CRC:type:filename /D /E /F /FTP:A /G /H /J /K /L /M /MD /N[dejnrstz] /O /O:[-]acdeginorstuz /P /Q /R /S[[+]n] /SX /T /U /UF /V[n] /W /WAIT=n /X /Z] [@file ] source [+] ... [/A|/B] [TO:] target [...] [/A|/B]|
|source||A file or list of files or a device to copy from|
|target||A file, directory, or device to copy to|
|@file||A text file containing the names of the source files, one per line (see @file lists for details)|
Supports command dialog, attribute switches, extended wildcards, ranges, multiple file names, delayed variable expansion, and include lists. Date, time, size or exclude ranges anywhere on the line apply to all source files. Use wildcards with caution on LFN volumes; see LFN File Searches for details.
Can be used with FTP / FTPS / TFTP / HTTP / HTTPS Servers.
If you don't specify any arguments, COPY will display its command dialog.
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:
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:
copy file1 e:\mydir
When you COPY files to or from an LFN drive, you must quote any file names which contain white space or special characters.
If you specify the /C, /CF, /R, /U, or /UF options, COPY will append a ! to the copy specifier if the target exists and is being overwritten. For example:
[d:\] copy file1 file2
file1 =>! file2
To emulate an approach used by some implementations of CMD, see the COPYCMD topic.
COPY sets three internal variables:
|%_copy_dirs||The number of directories created|
|%_copy_files||The number of files copied|
|%_copy_errors||The number of errors|
You can copy several files at once by using wildcards:
copy *.txt e:\mydir
You can also list several source files in one command. The following command copies 3 specific files from the current directory to the \MYDIR directory on drive E:
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:
copy e:\mydir\*.txt;*.doc;*.bat a:\
If there is only one parameter 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 from the current directory on drive A to the current directory on the current drive:
If there are two or more parameters on the line separated by spaces, then COPY assumes that the last parameter is the destination and copies all source files to this new location. If the destination is a drive, directory, or device name, 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):
copy a:*.dat c:\mydir\
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 single destination file, when you really meant to copy them individually to a destination directory.
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 more information on CLIP:.
A plus sign + tells COPY to append two or more source 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 MEMO2 and MEMO3 to MEMO1 and leave the combined contents in the file named MEMO1:
To append the same three files but store the result in BIGMEMO:
copy memo1+memo2+memo3 bigmemo
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.
You cannot append a file to itself.
If you have appropriate permissions, you can copy to and from Internet URLs (FTP, TFTP and HTTP). Many FTP servers use case sensitive file systems. For example:
copy ftp://ftp.abc.com/xyz/index index
Files copied to or from FTP/HTTP Servers are normally transferred in binary mode. To perform an ASCII transfer use the /L switch. File descriptions are not copied when copying files to an Internet URL.
COPY supports the special syntax
copy con: ftp:...
to directly copy text from the console to an ftp location.
Wildcard characters such as * and ? will be treated as wildcards in FTP URLs, but will be treated as normal characters in HTTP URLs.
Note: The /G option (percentage copied) may report erratic values during transfer of files larger than 4 Gb (an ftp limitation) and during http downloads.
You can also use the IFTP command to start an FTP session on a server, and then use an abbreviated syntax to specify the files and directories you want. For more information, see Using FTP/HTTP Servers and IFTP.
•NTFS File Streams
COPY supports file streams on NTFS drives. You can copy an individual stream by specifying the stream name, for example:
copy myfile:mystream stream.copy
If no stream name is specified the entire file is copied, including all streams. However, if you copy a file to a drive or device which does not support streams, only the file's primary data is copied; any additional streams are not processed.
See NTFS File Streams for additional details.
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:
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:
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.
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:
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:
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 destination file. See /K below for a special note if you are running under Novell NetWare.|
|/Z||Forces COPY to overwrite an existing destination file regardless of its attributes.|
You can copy files to multiple destinations with the TO: option. For example, to copy letter.doc to three different directories:
|copy letter.doc TO: \save\ f:\backups\ q:\letters\|
Note: The wildcard expansion process will attempt to allow both CMD-style "extension" matching (assumes only one extension, at the end of the word) and the advanced TCC string matching (allowing things like *.*.abc) when an asterisk is encountered in the destination of a COPY command.
COPY supports regular expression back references in the target name. If you are using back references, you must also use a regular expression in the source name. The syntax is:
copy ::filename ::target
COPY supports connected web folders. If an HTML file (i.e., with an .htm or .html extension) is copied, COPY will look for a folder in the same directory with the same name and an extension of ".files". If it is found, the .files directory will be copied to the target directory. You can disable connected web folders by setting the registry key:
You can override the default HTTP proxy server, proxy user, and proxy password (set in TCMD.INI) with the /Proxy... options.
The /A (ASCII copy) and /B (binary copy) 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. All other options apply to all filenames on the command line, no matter where you put them.
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.
|/=||Display the COPY command dialog to help you set the filename and command line options. The /= option can be anywhere on the line; additional options will set the appropriate fields in the command dialog.|
|/A||If you use /A with a source filename, the file will be copied up to, but not including, the first Control-Z (ASCII: 26) character in the file. If you use /A with a destination filename, a Control-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, rather than a disk file.|
This option applies to the filename immediately preceding it, and to all subsequent filenames until the file name preceding the next /A or /B option.
|/A:...||Select only those files that have the specified attribute(s) set. See Attribute Switches for information on the attributes which can follow /A:. 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 switch, above. Do not use /A: with @file lists. See @file lists for details. Hidden or system files selected by this option overwrite hidden or system files.|
You can specify /A:= to display a dialog to help you set individual attributes.
|/B||If you use /B with a source filename, the entire file is copied; Ctrl-Z characters, if any, in the file are considered ordinary data to be copied. Using /B with a destination filename prevents addition of a Ctrl-Z to the end of the destination file. /B is the default unless source files are appended to the target file, or the target is a device, e.g., NUL.|
This option applies to the filename immediately preceding it, and to all subsequent filenames until the file name preceding the next /A or /B option.
|/C||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 files not already in the target directory. Before using /C in a network environment, be sure to read the note under /U. Do not use /C with @file lists. See @file lists for details.|
|/CF||Copy files only if the destination file exists and is more than 2 seconds older than the source (see also /C and /UF). Do not use /CF with @file lists. See @file lists for details.|
type - The type of CRC to create. Possible types are:
filename - The file that contains the CRC and file names (one per line).
|/E||(No error messages) Suppress all non-fatal error messages, such as File not found or Can't copy file to itself. Fatal error messages, such as Drive not ready, will still be displayed. This option is most useful in batch files and aliases.|
|/G||Displays the percentage copied, the transfer rate (in Kbytes/second), and the estimated time remaining. Useful when copying large files across a network or via FTP to ensure the copy is proceeding. When /V is also used, reports percentage verified.|
|/H||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.|
|/I"text"||(Match descriptions) Select source files by matching text in their descriptions. See Description Ranges for details.|
|/J||Copy the file in restartable mode. The copy progress is tracked in the destination file in case the copy fails. The copy can be restarted by specifying the same source and destination file names. /J will not work with HTTP or FTP files.|
|/K||(Keep read-only attribute) To maintain compatibility with CMD, COPY normally maintains the hidden and system attributes, sets the archive attribute, and removes the read-only attribute on the target 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.|
|/LD||When used with /S, if the source is a symbolic or hard link to a directory, COPY will create the link in the target directory instead of copying the subdirectory tree.|
|/M||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 file will not be cleared after copying; to clear it use the /X switch, or use ATTRIB. Do not use /M with @file lists. See @file lists for details.|
|/MD||Create the target directory if it doesn't exist. Note that you *must* either terminate the target directory name with a trailing \ or specify a filename component; otherwise COPY cannot tell what you want for the directory and what you want for the filename.|
|/N||Do everything except actually perform the copy. This option is useful for testing what the result of a complex COPY command will be. /N displays how many files would be copied.|
A /N with one or more of the following arguments has an alternate meaning:
d Skip hidden directories (when used with /S)
e Don't display errors.
j Skip junctions (when used with /S)
n Don't copy/update the file descriptions
r A COPY /W will delete to the recycle bin (unless the file matches the RECYCLEEXCLUDE environment variable).
s Don't display the summary.
t Don't update the CD / CDD extended directory search database (JPSTREE.IDX).
z Skip system directories (when used with /S)
You may use any combination of the sorting options below. If multiple options are used, the listing will be sorted with the first sort option as the primary key, the next as the secondary key, and so on:
|n||Sort by filename and extension, unless e is explicitly included. This is the default.|
|-||Reverse the sort order for the next sort key|
|a||Sort names and extensions in standard ASCII order, instead of numerically when numeric substrings are included in the name or extension.|
|c||Sort by compression ratio|
|d||Sort by date and time (oldest first); also see /T:acw|
|e||Sort by extension|
|g||Group subdirectories first, then files|
|i||Sort by description|
|o||Sort by owner|
|r||Reverse the sort order for all options|
|s||Sort by size|
|t||Same as d|
|z||Same as s|
The /O:... option saves all of the matching filenames and then performs the copy. This avoids the potential problem of copying files more than once.
|/P||Ask the user to confirm each source file. Your options at the prompt are explained in detail under Page and File Prompts. Note: the Copy Prompt on Overwrite configuration option can be used to force prompting at the command line only. See also: the /Q option below.|
|/Q||Don't display filenames, percentage copied, total number of files copied, etc. When used in combination with the /P option above, it will prompt for filenames but will not display the totals. This option is most often used in batch files. See also /T.|
|/R||Prompt the user before overwriting an existing file. Your options at the prompt are explained in detail under Page and File Prompts. See also: the Copy Prompt on Overwrite configuration option. (For compatibility with CMD, a /Y option on the command line is changed to /R.)|
|/S||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. Do not use /S with @file lists. See @file lists for details.
If you specify a number after the /S, COPY will limit the subdirectory recursion to that number. For example, if you have a directory tree "\a\b\c\d\e", /S2 will only affect the "a", "b", and "c" directories.
If you specify a + followed by a number after the /S, COPY will not copy any files until it gets to that depth in the subdirectory tree. For example, if you have a directory tree \a\b\c\d\e, /S+2 will not copy anything in \a or \a\b.
|/SX||Copy the subdirectory tree to a single target directory (implies /S). For example, to copy all of the .EXE files in "c:\files" and all of its subdirectories to the directory "d:\exefiles":|
copy /sx c:\files\*.exe d:\exefiles\
|/T||Turns off the display of filenames, like /Q, but does display the total number of files copied.|
|/U||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. Do not use /U with @file lists. See @file lists for details. When used with file systems that have different time resolutions (such as FAT and NTFS), /U will attempt to use the "coarsest" resolution of the two.|
|/UF||Copy each source file only if it is more than 2 seconds newer than a matching destination file or if a matching destination file does not exist (see also /CF and /U). Do not use /UF with @file lists. See @file lists for details.|
|/Vn||Verify each disk write by performing a true byte-by-byte comparison between the source and the newly-created target file. This option will significantly increase the time necessary to complete a COPY command. /V will not work for FTP, TFTP, or HTTP copies. If n is set, it specifies the number of retries (0-n) if the verification fails. If n is specified and all of the retries fail, the target file will be deleted.|
|/W||Delete files in the target directory that don't exist in the source directory. (Use this instead of SYNC when you only want to synchronize "one way".)|
/WAIT=n Pause for n milliseconds between each block copied from the source to the target file. This is useful for users with slow networks and very large file copies; it prevents COPY from monopolizing all of the network I/O.
|/X||Clear 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. /X should not be used with multiple targets, because the archive attribute will be cleared after the first copy.|
|/Y||If you have the COPY Prompt on Overwrite option set, you can suppress the prompt with /Y.|
|/Z||Overwrite destination files regardless of their attributes. Without this option, COPY will fail with an "Access denied error" if the destination file has its read-only attribute set, or (depending on other options) its hidden or system attribute set. Required to overwrite read-only targets regardless of other options. Required to overwrite hidden or system targets unless the source also has the attribute, and either /H or /A: is used to select it.|