Both xcopy and copy are commands in windows.
The advantage of xcopy is that you can exclude unnecessary files or folders for copying.
However, this command is really not easy to use. It is not as simple as the help of windows.
Let's take a look at how xcopy is written.
/Exclude: file1 [+ file2] [+ file3]...
List of objects containing strings. Each string
It must be in a separate row of the file. If any
Absolute path of the string and the file to be copied
The file will not be copied.
For example, strings such as/obj/or. OBJ are excluded.
All files under the OBJ directory or
File with the. OBJ extension.
Next we will test
Create two folders. One is data and the other is backup.
Directory tree
Z :.
│
├ ── Data
│ ─ ── Bad
│ └ ── Good
│ Bad.txt
│ Good.txt
│ 1.bad
│ 2.bad
│ 3.bad
│ 5.bad
│ 4.bad
│
Backup
Our goal is to copy all the folders marked with good and files to the backup directory, and exclude the folders and directories marked with bad.
Write the following command with xcopy help
Xcopy/e/S/H/exclude: uncopy.txt Z:/data/Z:/backup/
Uncopy.txt contains the files and folders we want to exclude.
The content is as follows:
/Bad/
Bad.txt
. Bad
Xcopy/e/S/H/exclude: uncopy.txt Z:/data/Z:/backup/do you think it is wrong to execute this command first?
OK. Let's take a look.
Z:/> xcopy/e/S/H/exclude: uncopy.txt Z:/data/Z:/backup/
Invalid path
Copied 0 files
This is really interesting. The path is invalid.
Xcopy/e/S/H/exclude: uncopy.txt Z:/data/Z:/backup/the problem lies in Z:/data /.
The correct statement should be Z:/data, not Z:/backup /.
After the change, we will execute it again.
Z:/> xcopy/e/S/H/exclude: uncopy.txt Z:/Data Z:/backup/
Z:/data/Good/good.txt
Copied one file.
Let's take a look at the backup directory tree.
Z :.
└ ── Good
Good.txt
Comparison
Z :.
├ ── Bad
└ ── Good
Bad.txt
Good.txt
1. Bad
2. Bad
3. Bad
5. Bad
4. Bad
We successfully copied the folder marked with good and the file.
This is a good practice. For example, if the file on your hard disk is damaged, you can use this method to avoid the damaged file.
Or avoid unnecessary files, just copy what you want.
You can try this method when the wildcard character is not easy to use.
THX: 10 important help for this test