On the exclusion of copy in xcopy

Time:2021-5-4

But this command doesn’t really work   It’s not as simple as the windows help   Let’s explain it in detail
Let’s first see how xcopy‘s help is written
/EXCLUDE:file1[+file2][+file3]…
Specifies the list of files that contain strings. Every string
Must be in a separate line of the file. If there’s any
The absolute path between the string and the file to be copied
That file will not be copied.
For example, specify  \ obj\   or  . obj   Will be excluded
catalogue   obj   All files below or with
.obj   File with extension.
Now let’s do the experiment
Create two folders   One is called data   One is called 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 the good marked folder and files to the backup directory   The folder and directory marked bad are excluded
Write the following command with the help of xcopy
xcopy /e /s /h /exclude:uncopy.txt z:\data\ z:\backup\
Uncopy.txt contains the files we want to exclude   as well as   folder
The content is as follows
\bad\
bad.txt
.bad
xcopy  / e  / s  / h  / exclude:uncopy.txt   z:\data\   z:\backup\   Don’t carry out this order yet   Do you think it’s wrong?
ok   Let’s do it
Z:\>xcopy /e /s /h /exclude:uncopy.txt z:\data\ z:\backup\
invalid path
Copied   0   Files
That’s interesting   ha-ha   invalid path
xcopy  / e  / s  / h  / exclude:uncopy.txt   z:\data\   z:\backup\   The problem is Z: data\   above
The correct way to write it is Z: data   No\   And the one behind it   z:\backup\   You can do it or not
We’ll implement it after we change
Z:\>xcopy /e /s /h /exclude:uncopy.txt z:\data z:\backup\
Z:\data\good\good.txt
Copied   one   Files
Take a look at the directory tree of backup
Z:.
└─good
good.txt
contrast
Z:.
├─bad
└─good
bad.txt
good.txt
1.bad
2.bad
3.bad
5.bad
4.bad
We successfully copied the folder and files that only marked good
This is a good usage   such as   A file on your hard disk is damaged   You can use this   Method to avoid damaged files
Or   avoid   Some unnecessary files   Just copy what you want
When the wildcard is not easy to use   You can try this method
thx:10 Important help for this test