Copies one or more files to the location you specify.
This command can also be used to combine files. When more than one file is copied, the operating system displays each filename as the file is copied.
COPY [/Y | /-Y] [/A | /B] source [/A | /B] [+ source [/A | /B] [+ ...]] destination [/A | /B]] [/D] [/N] [/V] [/Z]
For information about copying directories and subdirectories,
see the XCOPY command.
ROBOCOPY - Robust File and Folder Copy
SCOPY - File Copy with Security
MOVE - Move a file from one folder to another
Equivalent Linux BASH commands:
cp - Copy one or more files to another location
install - Copy files and set attributes
You can set the %COPYCMD% environment variable to specify whether you want the COPY, MOVE, and XCOPY commands to prompt you for confirmation before overwriting a file, whether issued from the command prompt or a batch file.
To force the COPY, MOVE, and XCOPY commands to prompt you before overwriting in all cases, set the %COPYCMD% environment variable /-Y. To force these commands to overwrite in all cases without prompting you, set the %COPYCMD% environment variable to /Y.
Typing any of these commands with the /Y or /-Y switch overrides all defaults and the current setting of the %COPYCMD% environment variable.
You can substitute a device name for one or more occurrences of source or for destination.
When destination is a device (for example, COM1 or LPT1), the /B switch causes the operating system to copy data to the device in binary mode. In binary mode, all characters (including such special characters as CTRL+C (^C), CTRL+S (^S), CTRL+Z (^Z), and carriage return) are copied to the device as data. Whereas, omission of the /B switch causes the operating system to copy data to the device in ASCII mode. In ASCII mode, such special characters as those previously listed may cause the operating system to take special action during the copying process.
If you do not specify a destination file, the operating system creates a copy with the same name, creation date, and creation time as the original file, placing the new copy in the current directory on the current drive. If the source file is on the current drive and in the current directory and you do not specify a different drive or directory for the destination file, the COPY command stops and the operating system displays the error message:
File cannot be copied onto itself 0 File(s) copied
If the operating system cannot verify a write operation, it displays an error message. Although recording errors rarely occur with the COPY command, the /V switch lets you verify that critical data has been correctly recorded. The /V switch also slows down the COPY command, because the operating system must check each sector recorded on the disk.
The effect of an /A or /B switch depends upon its position on the command-line. When the /A or /B switch follows the source filename, COPY performs as shown in the list:
/A Treats the file as an ASCII (text) file and copies data that precedes the first end-of-file character. COPY does not copy the first end-of-file character or the remainder of the file.
/B Copies the entire file, including any end-of-file character.
When the /A or /B switch follows the destination filename, COPY performs as shown in the list:
/A Adds an end-of-file character as the last character of the file.
/B Does not add an end-of-file character.
If you specify more than one source, separating entries with a plus sign (+), COPY combines the files, creating a single file. If you use wildcards in source but specify a single filename in destination, COPY combines all files matching the filename in source and creates a single file with the filename specified in destination.
In either case, COPY assumes the combined files are ASCII files unless you specify the /B switch. (Do not combine non-ASCII files without specifying the /B switch; doing so can result in truncated files, since most binary files contain CTRL+Z (^Z) characters which cause COPY to behave as if it has reached the end of the file.)
If the name of the destination file is the same as the name of one of the files being copied (except the first file), the original contents of the destination file are lost. When this happens, COPY displays the message:
Content of destination lost before copy
To copy all of a directory's files and subdirectories, you should use the XCOPY command.
COPY does not copy files that are 0 bytes long; instead, it deletes such files. Use XCOPY to copy these files.
If you want to assign the current time and date to a file without modifying the file (AKA "TOUCH"), use a command in the format. The commas indicate the omission of the destination parameter.
COPY /B source+,,
This command copies a file and ensures that an end-of-file character (CTRL+Z) is at the end of the copied file:
COPY MEMO.DOC LETTER.DOC /A
To copy the NOTE.TXT file from the current drive and directory to the directory MYNOTES, and to prevent the operating system from prompting you before overwriting the destination file (if it already exists), type:
COPY NOTE.TXT MYNOTES /Y
To copy a file named ROBIN.TYP from the current drive and directory to an existing directory named BIRDS that is located on drive C, type:
COPY ROBIN.TYP C:\BIRDS
If the BIRDS directory doesn't exist, the operating system copies the file ROBIN.TYP into a file named BIRDS that is located in the root directory on the disk in drive C.
To copy several files into one file, list any number of files as source parameters on the COPY command-line. Separate filenames with a plus sign (+) and specify a filename for the resulting combined file:
COPY MAR89.RPT + APR89.RPT + MAY89.RPT REPORT
This command combines the files named MAR89.RPT, APR89.RPT, and MAY89.RPT from the current drive and directory and places them in a file named REPORT in the current directory on the current drive. When files are combined, the destination file is created with the current date and time. If you omit destination, the operating system combines the files and stores them under the name of the first specified file. For example, if a file named REPORT already exists, you can use the command to combine all four files in REPORT:
COPY REPORT + MAR89.RPT + APR89.RPT + MAY89.RPT
You can also combine several files into one by using wildcards:
COPY *.TXT COMBIN.NEW
This command combines all files in the current directory on the current drive that have the extension .TXT into one file named COMBIN.DOC, also in the current directory on the current drive.
If you want to combine several binary files into one by using wildcards, include the /B switch:
COPY /B *.EXE COMBIN.EXE
This prevents the operating system from treating CTRL+Z (^Z) as an end-of-file character.
CAUTION: If you combine binary files, the resulting file might not be usable due to internal formatting.
COPY combines each file that has a .TXT extension with its corresponding .REF file. The result is a file with the same filename but with a .NEW extension. Thus, COPY combines FILE1.TXT with FILE1.REF to form FILE1.NEW. Then COPY combines FILE2.TXT with FILE2.REF to form FILE2.NEW, and so on.
COPY *.TXT + *.REF *.NEW
The COPY command combines first all files with the .TXT extension, then all files with the .REF extension into one file named COMBIN.TXT:
COPY *.TXT + *.REF COMBIN.TXT
Copying information from the keyboard
The COPY command copies what you type at the keyboard to the OUTPUT.TXT file:
COPY CON OUTPUT.TXT
After you type this command and press ENTER, the operating system copies everything you type to the file OUTPUT.TXT. When you are finished typing, press CTRL+Z (^Z) to indicate that you want to end the file. The CTRL+Z (^Z) character will appear on the screen as "Z". You can also end a COPY CON command by pressing the F6 key. When you press F6, it generates the CTRL+Z (^Z) character, which appears on the screen as Z.
Copies information from the keyboard to the printer connected to LPT1:
COPY CON LPT1