Search notes:
cmd.exe - copy
Copy one file
The following command copies one file (a_file.txt
) into the directory p:\ath\to\destination\directory
. a_file.txt
must be located in the current directory .
C:\users\rene> copy a_file.txt p:\ath\to\destination\directory
If the destination does not refer to a directory, it is interrpreted as a new name for the file (thus the file is copied and renamed ):
c:\users\rene> copy another_file.txt p:\ath\to\destination\directory\renamed_file.txt
No creation of directories
If the destination directory does not exist, it won't be created. Rather, an error message is displayed (
c:\users\rene> copy hello.txt p:\ath\to\inexsting\directory\file.txt
The system cannot find the path specified.
0 file(s) copied.
Using source paths
The source file can also be given with a path, relative or absolute:
C:\users\rene> copy %appdata%\prg\file p:\ath\to\destination
Copying multiple files
Mulitple files can be copied in one command, however only to the same destination directory.
C:\users\rene> copy %appdata%\prg\* p:\ath\to\destination
Using wildcards
Of course, wildcards are possible. The following command copies all files in
src
whose
extension is
foo
to the directory
dest
.
C:\users\rene> copy src\*.foo dest
If the wildcard is used twice, the files are copied and their suffix renamed*.
C:\users\rene> copy *.txt *.txt.save
Updating a file's timestamp
The following command updates a file's timestamp, much as
touch
on Unix does. However, it won't create the file if it does not exist.
c:\> copy someFile.txt +,,
Options
/A
| /B
Indicates an ASCII text | binary file.
/D
Allow the destination file to be created decrypted destination Specifies the directory and/or filename for the new file(s).
/V
Verifies that new files are written correctly.
/N
Uses short filename, if available, when copying a file with a non-8dot3 name.
/Y
| /-Y
Suppresses | 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 the actual file the source link points to.
See also
xcopy.exe
to copy entire directory structures. Contrary to
copy
,
xcopy
is not a built-in command of
cmd.exe
but a «real»
executable