DOS file copy command


Let’s say that you need to put D: test\ test.txt Copy this file to the root directory of disk D, then use copy D:: test\ test.txt d: You can do it easily.

Of course, this is the simplest case, in actual use, it will encounter very complex situation.

If a file named test.txt Then, when you copy the past, the copy command will prompt you whether you want to overlay the original file, discard the copy, or overlay all the files. If you want to copy all the original files in batch, it’s very troublesome to select one by one. At this time, you can use the parameter / Y (which is equivalent to automatically selecting the yes option) to cover the original file without any prompt. The complete command is copy / y d:: Test\ test.txt d:\ 。

When copying, you need to change the name of the source file, such as test.txt When changing to 1.txt, you can directly use: copy D: test\ test.txt d: In other words, when specifying the destination path, directly specify the file name, then the new file name is the name of the source file after copying.

If the path to be copied has special symbols such as spaces and & marks, please use quotation marks to enclose these special characters, for example: copy “D:: Test ABC\ test.txt ” “d:\t&est”

In addition to the function of “copy” file, the copy command also has a unique skill: merge multiple files into one file. The specific format is: copy file 1 + file 2 + file 3 + Destination path \ \ new file name. For example: copy D:\ test.txt +d:\ abc.txt d:\test\ test.txt Then, put the test.txt and abc.txt The contents of the two files are merged into test.txt , and save it to the directory D:: – test.

Copy also has some parameters, but the above usage is commonly used. For more usage, please use copy /? To query in the command line window, which is easy to use.

It must be noted that copy can only copy files. For folder copying, you need to ask for another expert to use xcopy to copy. Xcopy is an advanced version of copy. It has more parameters and can realize more complex functions. It will be introduced separately in the future, and will not be explained here.