Copy command

Updated: 11/12/2023 by Computer Hope
copy command

The copy command allows users to copy one or more files to an alternate location.

Note

The copy command is used for complete files, to copy a directory, or multiple directories containing files, use the robocopy or xcopy command. To copy text in a file, see: How to copy and paste text to a document or another program.

Availability

Copy is an internal command and is available for the following Microsoft operating systems.

Copy syntax

Windows Vista and later syntax

COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination [/A | /B]]
source Specifies the file or files to be copied.
/A Indicates an ASCII (American Standard Code for Information Interchange) text file.
/B Indicates a binary file.
/D Allow the destination file to be created decrypted.
destination Specifies the directory or file name for the new file(s).
/V Verifies that new files are written correctly.
/N Uses short file name, if available, when copying a file with a non-8dot3 name.
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite an existing destination file.
/Z Copies networked files in restartable mode.
/L If the source is a symbolic link, copy the link to the target instead of to the actual file the source link points.

The switch /Y may be preset in the COPYCMD environment variable. This setting may be overridden with /-Y on the command line. The default is to prompt on overwrites unless COPY command is being executed in a batch script.

To append files, specify a single file for destination, but multiple files for source (using wildcards or file1+file2+file3 format).

Windows XP and earlier syntax

COPY [/A | /B] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination] [/A | /B]] [/V] [/Y | /-Y]
source Specifies the file or files to be copied.
/A Indicates an ASCII text file.
/B Indicates a binary file.
destination Specifies the directory or file name for the new file(s).
/V Verifies that new files are written correctly.
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite an existing destination file.

The switch /Y may be preset in the COPYCMD environment variable. This setting may be overridden with /-Y on the command line.

To append files, specify a single file for destination, but multiple files for source (using wildcards or file1+file2+file3 format).

Copy examples

copy *.txt c:\

In the example above, we are using a wildcard to copy all .txt files (multiple files) from the current directory to the c:\ root directory.

copy *.* a:

Copy all files in the current directory to the floppy disk drive.

Note

If there are hidden files, they're not copied. To copy all files including hidden files, use the xcopy command.

copy autoexec.bat c:\windows

Copy the autoexec.bat, usually found at root, and copy it to the Windows directory; the autoexec.bat can be substituted for any file(s).

copy win.ini c:\windows /y

Copy the win.ini file in the current directory to the Windows directory. Because this file already exists in the Windows directory it normally would prompt to overwrite the file. However, with the /y switch, you do not receive any prompt.

copy "computer hope.txt" hope

Copy the file "computer hope.txt" into the hope directory. Whenever you are dealing with a file or directory with a space, it must be surrounded with quotes. Otherwise, you get the "Getting 'The syntax of the command is incorrect' error." error.

copy myfile1.txt+myfile2.txt

Copy the contents in myfile2.txt and combines it with the contents in myfile1.txt.

copy con test.txt

Finally, create a file using the copy con command as shown above, which creates the test.txt file. Once the command above is typed, type the desired text. After creation is complete, save and exit the file by pressing Ctrl+Z, which creates ^Z, and press Enter. An easier way to view and edit files in MS-DOS is to use the edit command.