Solved

Batch File: XCOPY - Exclude Files

Posted on 2010-08-25
6
1,722 Views
Last Modified: 2012-05-10
Hi there,

Using following command line, I need to exclude the following files and folders.

My problem here is that the files containing wild cards are not excluded.


COMMAND LINE:
----------------------------------
XCOPY "!BasePath_Source!" "!BasePath_Dest!" /S /L /F /Y /D /EXCLUDE:Exclude.txt


Exclude.txt
----------------------------------
*.mp3
*.wma
*.wav
*.avi
*.mpg
~*.*
*.tmp
Thumbs.db
\temp\
\System Volume Information\
\RECYCLER\
\Virtual Machines Garage\
\Virtual Machines Microsoft\
\Virtual Machines VMWARE\


Thanks for your help,
Rene
0
Comment
Question by:ReneGe
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Cluskitt
ID: 33521305
I could be wrong (it's been a while), but I think you don't need * for any of them.
Not sure how to exclude the ~*.* though. If I remember correctly, the ".mp3", etc, are what's matched. There is already assumed to be a "*.mp3*" on all of them. Would wait for other expert opinions though (as I said, long time :)
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 400 total points
ID: 33521325
/EXCLUDE uses exact string matching, not pattern matching. That is: No wildcards, please. Your list should hence contain

.mp3
.wma
.wav
.avi
.mpg
~
.tmp
Thumbs.db
\temp\
\System Volume Information\
\RECYCLER\
\Virtual Machines Garage\
\Virtual Machines Microsoft\
\Virtual Machines VMWARE\

But that is inprecise, in particular with the tilde - it will exclude names like   a~b   also.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 33521376
The only means to perform exactly what you want is to create the exclusion list for ~*.* dynamically:

@echo off
(for /F "tokens=*" %%F in ('dir /s/b /a:-d C:\~*.*') do @echo %%F) > exclude~.txt
XCOPY "!BasePath_Source!" "!BasePath_Dest!" /S /L /F /Y /D /EXCLUDE:Exclude.txt+exclude~.txt
del exclude~.txt

and leave the ~ out of exclude.txt.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 100 total points
ID: 33521380
Maybe you could add:
dir ~*.* /s /b > exclude.txt

Then append the rest of the file, and only after that will you run XCOPY.
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 33521417
Or you can use Qlemo's. It's more effective :D
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33521607
Thanks guys for all your help.

.mp3
.wma
.wav
.avi
.mpg
~
.tmp
Thumbs.db
\temp\
\System Volume Information\
\RECYCLER\
\Virtual Machines Garage\
\Virtual Machines Microsoft\
\Virtual Machines VMWARE\

Works for me since it is the fastest solution.

Cheers,
Rene


*** Qlemo & Cluskitt ...ROCKS... ***
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now