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.
A simple use of copy command is given below.
copy File Destinationpath
If you need to copy multiple files, then the syntax will be like below.
copy file1 file2 file3 Destinationpath
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\
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.
As in example above, copy the file but name it as 2.doc
c\> copy c:\data\documents\1.doc c:\data\newdocs\2.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.
Xcopy command syntax and examples