Before giving examples of the 'COPY' command, some words on TAB completion. Type:
D:\test>CD my Doc [ENTER]This command -as we have seen- results in the prompt
D:\test\my Doc>To avoid much typing, use TAB completion. Type:
D:\test\my Doc>CD .. [ENTER]The prompt will be D:\test> again. Type now:
D:\test>CD myand press TAB. The result is:
D:\test>CD my DocPress Enter and you'll see the prompt
D:\test\my Doc>If your command does not work, try to surround names with space(s) by double quotation marks (double apostrophes).
D:\test>CD my Doc [ENTER]does not work, try
D:\test>CD "my Doc" [ENTER]To be sure, I'll use in this tutorial the double quotation marks in case of names with space(s).
D:\test>COPY file1.txt "my Doc" [ENTER]To copy the files 'file1.txt', 'file2.dat', 'file2.txt' and 'file3.txt' to 'my Doc', use Glob patterns:
D:\test>COPY file?.* "my Doc" [ENTER]where the question mark ? refers to the number 1, 2 and 3 and the characters '.*' matches all extensions.
D:\test>COPY *.jpg "my Doc" [ENTER]will copy the image files with the extension .jpg into the subdirectory 'my Doc'. However, loading those images into an image viewer will probably give error. To avoid this, you should use the binary mode: in this case the files are copied byte for byte. Simply add the switch '/B' to the 'COPY' command:
D:\test>COPY /B *.jpg "my Doc" [ENTER]
D:\test>COPY /A file?.* "my Doc"\combinedText.txt [ENTER]The text files file1.txt, file2.txt, file2.dat and file3.txt are concatenated. The switch '/A' refers to the ASCII-mode, with '/B' you switch to the binary mode.
D:\test>COPY /B *.mp3 "my Doc"\CombinedBin.mp3 [ENTER]The CombinedBin.mp3 contains now both mp3 files of the current directory.
FOR %variable IN (set) DO command [command parameters]Study the next loop:
D:\test>FOR %i IN (file1.txt fiel2.dat) DO COPY /A /V %i "my Doc" [ENTER](set) is replaced by a list of two files that are separated by a space: (file1.txt file2.dat). The variable %i takes these list values: first %i has the value 'file1.txt' and then 'file2.dat'.
D:\test>ROBOCOPY D:\test "D:\test\my Doc" file1.txt file2.dat [ENTER]To copy all text files from the current directory and all subdirectories, use the switch '/R' and '*.txt'
D:\test>FOR /R %i IN (*.txt) DO COPY /A /V %i D:\tmp [ENTER](you have to make the target directory 'tmp' first!)
D:\test>ROBOCOPY /S D:\test D:\tmp *.txt [ENTER]With the switch '/S' the '.txt' files from subdirectories will be copied also.
D:\test>ROBOCOPY /S /E D:\test D:\tmp [ENTER]copies all files and subdirectories ('/S'), empty ones inclusive ('/E')!