Solved

using xcopy, but excluding one directory

Posted on 2004-04-02
7
6,011 Views
Last Modified: 2007-12-19
I have a batch script where I want to xcopy the contents of my Y drive to my X drive, but I want to exclude Y:\FremontTCM, which is a directory with a bunch of subdirectories and files.  The following command:

xcopy  /e /exclude:y:\fremonttcm y:\* x:\*

does not work.  I know that the /exclude must have a filename to read from.  What do I need to do here to get this to work?
Thanks!

0
Comment
Question by:texasreddog
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 32

Expert Comment

by:LucF
ID: 10741533
Hi texasreddog,

Almost right, you just need to add one backslash:
> xcopy  /e /exclude:y:\fremonttcm\ y:\* x:\*


Greetings,

LucF
0
 

Author Comment

by:texasreddog
ID: 10741576
I tried running the command, and I get this.  It's still looking for a file.
By the way, both x:\ and y:\ are mapped network drives, if that is causing a problem.

C:\tcm>xcopy  /e /exclude:y:\fremonttcm\ y:\* x:\*
Can't read file: y:\fremonttcm\

0 File(s) copied
0
 
LVL 32

Expert Comment

by:LucF
ID: 10741667
ah... have you tried:

xcopy y:\* x:\* /e /exclude:y:\fremonttcm\
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:texasreddog
ID: 10741726
I tried that, but no luck.  When I put

y:\fremonttcm\

into a text file called excludefremont.txt, then ran:

xcopy y:\* x:\* /e /exclude:excludefremont.txt

then that runs.  So apparently, the only way xcopy will work is to put the excludes into a text file.  You can't run it by specifying your excludes on the command line.  Correct me if I'm wrong.
0
 
LVL 20

Accepted Solution

by:
Dufo G. Belski earned 200 total points
ID: 10741811
I've been following this thread with interest.  xcopy /? is very confusing about the exclude syntax.  This link makes it explicit that the /exclude switch *is* looking for a file containing strings to exclude.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx

Who knew?
0
 

Expert Comment

by:sylkin
ID: 11026890
here's a good example:

http://www.ekho.com/Training_Videos/XCOPY_NOTES.pdf

you want to exclude a file which contains the files extensions that
you don't want:

xcopy drive_A_stuff  to_drive_B_stuff  /EXCLUDE:junk.txt

where junk.txt is:

.mp3
.zip
.etc...

(one extension per line)


Paul Blue
0
 

Expert Comment

by:sylkin
ID: 11028542
also, the EXCLUDE .txt file must be in the same directory as the .bat file
if you are just using "/EXCLUDE:junk.txt"

Blue
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
avoiding the dashes in the sqlcmd output... 1 581
MailSend Attachments 41 184
Check Disk (CHKDSK) on all volumes and fix if needed. 8 198
For loop to add numbers 3 85
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question