1.

Solve : Exclude folders from XCOPY instead of just file names??

Answer»

I have used EXCLUDE before to avoid XCOPY'ing certain FILES. But am trying to figure out if there is a way to EXCLUDE folders by Folder Name or not.

OS I am working with is Windows XP Pro BTW

Quote

/EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  Each string
               should be in a SEPARATE line in the files.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.

Basically I want to xcopy the contents from My Documents and exclude the following folder names

Quote
DYMO LABEL
My Music
My Pictures
My Videos

I know that I can just write a batch pointing out exactly what to grab, but as folders are added this will mean that I'd have to edit my batch accordingly to grab those as well. So I figured I'd check to see if there was an Exclude Trick to target Folder Names to exclude from xcopy's scope?

I suppose I could also perform a wildcard exclusion such as *.jpg *.mp3 etc to avoid certain file types from being targeted that are in those locations. And if there is no way to exclude by folder names I MIGHT just have to create a wildcard listing of file types to exclude. Trying to remember how I did that a while back... I think it was like Quote
xcopy *.* e:\*.* /s/d/y/exclude:<Exclusion_List.txt
to read in exclusion list text file and process, and exclusion list was like this format of 1 line per exclusion
Quote
*.jpg
*.bmp
*.MP3
*.MP4
*.wav
So why aren't you using this for your exclude?
\DYMO LABEL\
\My Music\
\My Pictures\
\My Videos\Adding

Quote
\DYMO LABEL\
\My Music\
\My Pictures\
\My Videos\

in Exclusion_List.txt with instruction of

Quote
xcopy *.* e:\*.* /s/d/y/exclude:<Exclusion_List.txt

Still copies the folders and contents to E: when run from My Documents where the listed folders are within scope deeper ( My Documents\My Music\... etc )   
Quote from: DaveLembke on July 30, 2012, 07:52:30 AM
xcopy *.* e:\*.* /s/d/y/exclude:<Exclusion_List.txt

Try that without the redirection character. Quote from: foxidrive on July 30, 2012, 08:03:47 AM
Try that without the redirection character.
Yeah, what possessed you to use the < with that command. Gonna give that a try...  redirector got stuck in there because I have been playing in MYSQL prompts with batches for too long... sort of same issue I had way back when between DOS and Linux command prompts and / and \  ..LOL

Still an issue... its still grabbing folders that are unwanted with

Quote
xcopy *.* e:\*.* /s/d/y/EXCLUDE:Exclusion_List.txt

hmm...

Exclusion_List.txt file has just this in it and verified spelling and case even though case shouldnt matter if file name matches "Exclusion_List.txt" in DOS shell, so its not missing it due to any naming typos.

Quote
\DYMO LABEL\
\My Music\
\My Pictures\
\My Videos\

Both the batch file and the exclusion text file are in same location, so it should read in contents to exclude from

UPDATE: Also tried

Quote
"\DYMO LABEL\"
"\My Music\"
"\My Pictures\"
"\My Videos\"

to see if the spaces in folder names were causing the issue...   Also tried this pull path in text file to point directly with wildcards to relate all files to exclusion at unwanted folders, even though should be unecessary to have to point exclusively full paths to exclude, as well as account for spaces in folder names by encapsulating it with " " and still having folders and files which should be ignored xcopied across.

Quote
"C:\Documents and Settings\Dave\My Documents\DYMO LABEL\*.*"
"C:\Documents and Settings\Dave\My Documents\My Music\*.*"
"C:\Documents and Settings\Dave\My Documents\My Pictures\*.*"
"C:\Documents and Settings\Dave\My Documents\My Videos\*.*"

 It works fine.

Put this batch file in a folder with a few files and a couple of folders and run it.  In my test it ignores every folder and file under .\abc\


Code: [Select]echo off
md "abc\DYMO LABEL\"
md "abc\My Music\"
md "abc\My Pictures\"
md "abc\My Videos\"

echo abc>"abc\DYMO LABEL\abc.txt"
echo abc>"abc\My Music\abc.txt"
echo abc>"abc\My Pictures\abc.txt"
echo abc>"abc\My Videos\abc.txt"

(
echo \DYMO LABEL\
echo \My Music\
echo \My Pictures\
echo \My Videos\
)>Exclusion_List.txt


xcopy *.* c:\def\*.* /s /d /y /EXCLUDE:Exclusion_List.txt
pause
It is not matching the leading back slash because you were running the command from the ROOT of the My Documents folder.
Thanks for all your help everyone. Getting my 2 typos worked out fixed it!   

Quote
DYMO LABEL\
My Music\
My Pictures\
My Videos\

I personally would do it this way otherwise you are copying over the exclude file and the batch file if you are using a batch file.
Code: [Select]xcopy "My Documents\*.*" H:\backup /s /d /y /EXCLUDE:Exclude.txtThen you can use the leading back slash for the Exclude file.I'm doing something similar, but want my .bat file to live in a different directory. This script seems to work in a test case. Are there any problems with it?
Code: [Select]echo C:\Users\JT\Documents\Scan\abc\>Exclusion_List.txt
xcopy C:\Users\username\Documents\Scan\*.* B:\def\*.* /s /d /y /EXCLUDE:Exclusion_List.txt
pause
Thanks


Discussion

No Comment Found