Solved

Batch File: XCOPY - Exclude Files

Posted on 2010-08-25
6
1,761 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 70

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 70

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
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I fix this situation in GIT? 2 75
Java List 4 76
VB.Net Developer - Suggestions for Web Programming OnLine Learning 4 60
junit initializtion error 2 21
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 …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

739 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