Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch File: XCOPY - Exclude Files

Posted on 2010-08-25
6
Medium Priority
?
1,793 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 71

Accepted Solution

by:
Qlemo earned 1600 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 71

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

704 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