Files can be copied between directories using the copy command. The command is regular to Linux cp, but it doesn’t have all the capabilities that cp provides. You can only copy files with Windows copy, you cannot copy directories.
Copy Command Syntax & Examples:
Copy is explained below with examples of its syntax and use.
Contents of a file copy to another file –
copy sourceFile destination file
Example: c:\data\file1.doc to D:\backup\file2.doc
copy c:\data\file1.doc D:\backup\file2.doc
You will be prompted to confirm the existence of the destination file if it already exists. With the copy command, you can suppress this confirmation by using the /Y switch. Copy commands from batch files can be executed this way.
c\> copy /Y c:\dir1\subdir1\file1.txt c:\dir2\subdir2\file2.txt
The user won’t have to confirm overwriting the destination file if it already exists.
How to Copy the file to another directory?
The files will be copied with the same name when we specify a path for the destination. Changing the destination pathname allows us to assign a different name. See below for an example.
It is necessary to move the file 1.doc at c:\data\documents to the directory c:\data\newdocs
c\> copy c:\data\documents\1.doc c:\data\newdocs\
How to copy files with white space in the name?
We can wrap the file name in double quotation marks if it contains white space.
Here is an example: copying my resume.doc to another folder.
copy "my resume.doc" D:\data\
How to Copy the Multiple Files?
copy the command does not allow specifying multiple filenames. Wildcards can be used to identify multiple files. Then copy all of those files at once.
Read: Delete Directory from CMD Rmdir
The following example shows – This tutorial explains how to copy all Excel documents from the current folder to F:\backup
copy *.xls F:\backup\
To copy all files in the current folder to another folder
copy * D:\dir1\dir2
How to use environment variables?
In the copy command, we can specify the path to folders with environment variables. A TEMP, WINDIR, APPDATA, USERPROFILE, SystemRoot, ProgramFiles, etc.
Adding files to the user’s document folder, for instance.
Copy D:\file.pdf %HOMEPATH%\Documents\
Files copied by this command are stored in My Documents under the user’s current login.
You may also like: Restart or Reboot Windows Computer from CMD