Batch x/Copy dirs (excluding some)

Hi All;

I have to write a batch file that will copy folder sturcture, folder contents, whilst exlcuding some folders from the exisiting directory.
what i have so far is the following

xcopy /h /r /k /x /y /t /E . c:\ /exclude:c: emp\1.txt

where 1.txt contains

\1111
\1112\ <----ie the folders i dont want to copy

I got most of this from Google, but cannot seem to get it to work.

basicly i have 4-500 folders all named with either four or 5 digits which need to go from one server to another. There are also in this holding Dir about 6-7 folders with a large amount of data within them which i do not want to copy, tho these folders do not follow the same four or five digit naming convention.

Anyone got any ideas of how i can achieve this?

Thanks all!

Looks like it should work except for…

/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.

Try removing the /t?

removing the /t means that the folders are not copied, just the files within them unfortunatly, and still doesn’t exclude the folders stated :frowning:

would it be easier to zip up (tar/rar) all the folders, copy a single file, and unzip?

try putting your action parameters after the where-from-to logic and juggle the action parameters into the order expected if you want the full list just do… " xcopy /? "

Not saying it will work :chuckle:

i.e. xcopy . /EXCLUDE:c: emp\1.txt c:\ /E /H /R /K /X /T /Y

and each \whateverdirectory\ string need to be on a new line… ps don’t put quotes around the string or comma’s

Just done some testing myself. Removing the /t on the original line only shows copying of files, but it does create any empty directories too even if it doesn’t list them (due to /e).

Also I think I found out why the exclusions didn’t work. xcopy uses pattern matching on the path. The exclusion pattern doesn’t match if you use a relative path from current directory. Instead use full path, it seems to work.

e.g. xcopy /h /r /k /x /y /e d:\somewhere*.* c:\ /exclude:c: emp\1.txt

Spaceboy, zip might be an option, only prob is that it needs to be as quick as possible, for its going to be moving about 500 6meg files, and if i can just move them without any other processing then that would be best.
PMM - are you saying that i just have it the wrong way round?
Mackerel, are you saying that in my exclusions file i need the full direcotry path and not just the names ? for your EG looks remarkably simular to my own example?

Cheers for the input tho guys!

Nope. You have two choices:
Specify the full source path on the xcopy command, not use relative or current.
Specifically use something like
xcopy /h /r /k /x /y /e [b]d:\somewhere[/b]. c:\ /exclude:c: emp\1.txt
not
xcopy /h /r /k /x /y /e . c:\ /exclude:c: emp\1.txt

As the original command without /k stood, it would generate paths in the format of c:folder\file.ext - note there is no leading \ so the pattern does not match. If you use the full source, it seems to then use the format of c:\somewhere\folder\file.ext and file matching works.

Alternatively you could specify the exclusions without the leading \ so that patterns will match regardless, but that might match other directory names at the end so might include more than you want. e.g. excluding ‘\1234’ would only match ‘\1234’ but ‘1234’ might also match ‘\01234’

Right thats something i will test when back in work tomz!

I would do it the old fashion way…Copy everything then run a batch to delete the files not needed. Yes I know not a perfect way but it works!