Solved

Batch File: XCOPY - Exclude Files

Posted on 2010-08-25
6
1,744 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 69

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 69

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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

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.

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…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …

840 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