≡ Menu

Windows copy command syntax and examples

Using copy command, we can copy files from one directory to another directory. This command is similar to the Linux cp command, but it does not match with the full functionality of cp. Windows copy command can be used to copy files only, we can’t copy directories.

The syntax and usecases of copy command are explained below with examples.

Copy the contents of a file to another file

copy sourceFile destinationFile

Example: To copy a file from c:\data\file1.doc to D:\backup\file2.doc

copy c:\data\file1.doc D:\backup\file2.doc

If the destination file already exists you will be prompted for confirmation. To suppress this confirmation you can use /Y switch with copy command. This would be useful if you are executing copy command from a batch file.

c\> copy /Y c:\dir1\subdir1\file1.txt  c:\dir2\subdir2\file2.txt

If the destination file exists, the above command will overwrite the same without asking the user for confirmation.

Copy file to another directory

When we specify a directory path as the destination, the files will be copied with the same name. We can assign a different name by specifying the new name in the destination path. Example is shown below.

To copy the file 1.doc loated at c:\data\documents to the directory c:\data\newdocs

c\> copy c:\data\documents\1.doc  c:\data\newdocs\

Copy files with white space in name

If the file name has white space within it, we can wrap up the name in double quotes.
Example: To copy file, my resume.doc to another folder

 copy "my resume.doc"  D:\data\

Copy multiple files

We can’t specify multiple file names in copy command. However, we can use wildcards to identify a group of files and then copy all of them in a single command.
For example, to copy all excel files from current folder to another folder F:\backup

copy *.xls F:\backup\

To copy all files in current folder to another folder

copy *   D:\dir1\dir2

Use of environment variables

We can use environment variables in the copy command to specify the path of the folders. Like USERPROFILE, SystemRoot, ProgramFiles, TEMP, WINDIR, APPDATA, HOMEPATH.

For example, to copy a file to a user’s documents folder

Copy D:\file.pdf %HOMEPATH%\Documents\

The above command copies the file to the My Documents folder of the current logged in user.

You may also want to read

13 comments… add one
  • Anonymous

    Windows "copy" is funny. Type "copy 1 2" and the file "1" will be copied into a new file "2". Now separate them by a plus sign instead of a space (copy 1+2) and you'll concatenate 1 and 2 and replace the old file "1" with the result of the concatenation!

  • Techblogger

    Yes, we can concatenate two or more files using copy command. You need to separate the list of files using +. You can redirect the resultant data to a new file also.

    Copy 1+2 3

    The above command will not alter the file 1. It creates a new file 3 with the concatenated data of 1 & 2. If no file name is provided it stores the result in the first file.

  • John Fornes

    My Win7 cannot find a copy command, and when i run xcopy, a window flashes and exits.

    • Ryan

      I have the same problem. If you solved it, could you please explain how?

    • Erich

      If you can not find your copy.exe file, you can download it to your windows directory or C:\ Directory depending the setting on your OS you should also be able to copy and run it from system32 or system folder.

    • hekper

      go start ,run, type cmd [hit enter] or click start ,then in search box type cmd [hit enter]
      now type copy … [hit enter]

  • vf

    how can i combine 2 .exe files and be able to use both after concatenation

  • Ram

    Hi,

    I want to copy 2 different files(.exe,.config) from source to destination server of windows.
    can you please help me on this command.

    Thanks
    Ram

  • Abdelaziz

    Hello i have a problem with my cmd windows 7.when i try to copy a command. Like help > file.pdf. i mean in extension pdf because i have this problem only with .pdf extension but not with .txt.So whe i execute the command. No problem. Then when i go to open the file.pdf ftom user destination the file.pdf doesn’t open say that is corrupted.please do help me .thanks

  • sof

    i have a file contain many lines as sources and another file has the same numbre of lines as destinations. i want to copy first line as source( c:/test/*.txt) to first line in destination ( d:/test2/), secend line ( c:/test/*.pdf) to second line in destination ( E:/test3/)……

  • Ray

    Can I use the DOS/Windows “COPY” command in a BAT file to copy a file or a short string of text to computer memory and then paste (Ctrl +V) that string or file into a document?

  • Murthy

    I need a command to copy file with different name in same directory

  • Imre Varga

    Can you specify .. to go up one level in the directory tree, for example:

    copy file.txt ../imre/newcopy.txt

    to copy the file file.txt from my current directory to … up one level into the directory imre as the file newcopy.txt

    Thanks Imre

Cancel reply

Leave a Comment