Solved

Batch File: XCOPY - Exclude Files

Posted on 2010-08-25
6
1,710 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
Comment Utility
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
Comment Utility
/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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 100 total points
Comment Utility
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
Comment Utility
Or you can use Qlemo's. It's more effective :D
0
 
LVL 10

Author Comment

by:ReneGe
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

771 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

9 Experts available now in Live!

Get 1:1 Help Now