How to use the "exclude" option in xcopy?

M

May Young

Hi,

I use an xcopy command below but it doesn't do what I want. Instead, it
complains "cannot read file: .obj" and then stops.
xcopy c:\t1 c:\t2 /EXCLUDE:.obj

I want all .obj files are skipped during copying. Can someone help me?
Thanks. Tony
 
L

LiquidJ

The /EXCLUDE directive specifies a list of files which contain strings of
file names to exclude. For example, to do what you're trying to do, you'll
need to create a file, suppose we call it MyExcludes.txt. In this file,
there is just one filespec - ".obj" (w/o the quotes).

Then change the command to this:

xcopy c:\t1 c:\t2 /EXCLUDE:MyExcludes.txt


{L}
 
M

May Young

Thanks, LiquidJ. But if I want to have multiple filter strings in
MyExcludes.txt, then what delimiter should I use to sperate these
strings? I tired a blank or a + but they both failed. Thanks.

Tony
 
L

LiquidJ

Put each filter string on a separate line in the file (ie. separate them
with a CR+LF).


{L}
 
Joined
Dec 28, 2007
Messages
1
Reaction score
0
Current directory

I had success when I placed the text file in the current directory. Good ol' dos always looks at the current directory first. It may work if it is anywhere in your path, though I'm not sure how to comment it correctly if you had an absolute path to the file with the ":" being part of the syntax for EXCLUDE.
 
Joined
May 28, 2010
Messages
2
Reaction score
0
I think examples speak louder than explanations.I have in my batch file

the following line:


XCOPY L:\ P:\Backup /q/s/d/i/h/y/EXCLUDE:L:\Exclude_Names.txt

In my L drive I have a txt file called Exclude_Names.txt[no spaces

allowed] in which are the following lines:

\System Volume Information\

\RECYCLER\

AVG

desktop.ini

This excludes from copying to P the folders System Volume Information

and RECYCLER as well as excluding from copy any file/folder with the

string[letters] AVG and excludes the specific file desktop.ini.Each

exclusion must be on a seperate line of text.I could have had the

Exclude_Names.txt file on another drive if I had wanted.

Hope this helps anyone.
 
Last edited:
Joined
May 28, 2010
Messages
2
Reaction score
0
For completeness,I forgot one point,as I have never needed it.You could also have in your exclude file something like \test\test1\test22.txt to target nested file test22.txt
In other words anything can be the subject of exclusion,it is just a pity the DOS help is so pathetic and wrong!!Whoever wrote it should be shot.I think they thought a 'path' was for walking on only.Finally,if you want 2 or more exclusion txt files,why I wouldn't know,you need something like EXCLUDE:H:\Exclude_Names.txt+H:\Exclude_Names1.txt+H:\Exclude_Names2.txt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top