Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Exclude folders from XCOPY instead of just file names?  (Read 99801 times)

0 Members and 1 Guest are viewing this topic.

DaveLembke

    Topic Starter


    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Exclude folders from XCOPY instead of just file names?
« on: July 30, 2012, 07:00:41 AM »
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

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Exclude folders from XCOPY instead of just file names?
« Reply #1 on: July 30, 2012, 07:13:37 AM »
So why aren't you using this for your exclude?
\DYMO LABEL\
\My Music\
\My Pictures\
\My Videos\

DaveLembke

    Topic Starter


    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Exclude folders from XCOPY instead of just file names?
« Reply #2 on: July 30, 2012, 07:52:30 AM »
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 )   :(

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Exclude folders from XCOPY instead of just file names?
« Reply #3 on: July 30, 2012, 08:03:47 AM »
xcopy *.* e:\*.* /s/d/y/exclude:<Exclusion_List.txt

Try that without the redirection character.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Exclude folders from XCOPY instead of just file names?
« Reply #4 on: July 30, 2012, 08:09:03 AM »
Try that without the redirection character.
Yeah, what possessed you to use the < with that command.

DaveLembke

    Topic Starter


    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Exclude folders from XCOPY instead of just file names?
« Reply #5 on: July 30, 2012, 08:17:08 AM »
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...   :(

DaveLembke

    Topic Starter


    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Exclude folders from XCOPY instead of just file names?
« Reply #6 on: July 30, 2012, 09:34:57 AM »
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\*.*"

 :(

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Exclude folders from XCOPY instead of just file names?
« Reply #7 on: July 30, 2012, 10:02:49 AM »
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


Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Exclude folders from XCOPY instead of just file names?
« Reply #8 on: July 30, 2012, 10:04:47 AM »
It is not matching the leading back slash because you were running the command from the ROOT of the My Documents folder.

DaveLembke

    Topic Starter


    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Exclude folders from XCOPY instead of just file names?
« Reply #9 on: July 30, 2012, 10:43:24 AM »

Thanks for all your help everyone. Getting my 2 typos worked out fixed it!   ;D

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


Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Exclude folders from XCOPY instead of just file names?
« Reply #10 on: July 30, 2012, 10:46:02 AM »
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.

7670367



    Newbie

    • Experience: Experienced
    • OS: Windows 7
    Re: Exclude folders from XCOPY instead of just file names?
    « Reply #11 on: August 16, 2019, 07:43:40 AM »
    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