Purpose: Copy data between disks, directories, files, or physical hardware devices (such as your printer or serial port).
Format: COPY [/I"text"] [/A:... /C /D /E /F /FTP:A /G /H /J /K /L /M /MD /N[dejst] /O /P /Q /R /S[n] /T /U /V /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)
/LD (create link)
/A:... (Attribute select)
/MD (Create target directory)
/C(hanged source files)
/D (Copy encrypted files)
/O(nly if no target)
/E (No error messages)
/F (No empty subdirectories)
/FTP:A (ASCII copy)
/G (Display percentage)
/H (Include hidden files)
/I"text" (Match description)
/K (Keep read-only attribute)
/X (Clear archive)
/L Copy symbolic links
See also: ATTRIB, MOVE, and REN.
Supports 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.
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.
To emulate an approach used by some implementations of CMD.EXE, see the COPYCMD topic.
• Copying Files
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:.
• Appending Files
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.
• FTP Usage
If you have appropriate permissions, you can copy to and from Internet URLs (FTP, TFTP and HTTP). Many FTP servers, including our own ftp://jpsoft.com, 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.
• 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:
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.
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.
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.EXE-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 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:
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.
/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.
/B If you use /B with a source filename, the entire file is copied; <SUB> characters, if any, in the file are considered ordinary data to be copied. Using /B with a destination filename prevents addition of a <SUB> 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.
/D (Windows XP+ Only) Force copy of an encrypted file even when the target will be decrypted (for CMD.EXE compatibility).
/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.
/F When used with /S, COPY will not create any empty subdirectories.
/FTP:A Perform FTP transfers in ASCII mode, instead of the default binary mode.
/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.
/K (Keep read-only attribute) 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 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.
/L (Windows Vista or later only) If the source is a symbolic link, copy the link to the target instead of the actual file.
/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. /N does not prevent creation of destination subdirectories when it is used with /S.
A /N with one 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)
s Don't display the summary.
t Don't update the CD / CDD extended directory search database (JPSTREE.IDX).
/O Only copy the source file if the target file doesn't exist.
/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.EXE, 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.
/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.
/V 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.
/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.
/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