Jump to content

Xcopy in batch file


Recommended Posts

How should be the /exclude feature used. i can't find right syntax. Can anyone give me an example, how to exclude a dir. For example i want to copy opera profile to directory C:\XP without directories cache4 and images.

Link to comment
Share on other sites


this is from xcopy help

/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.

so; what command do you have so far? add the /exclude:file (or dir)

Link to comment
Share on other sites

so far i have

xcopy /Y "C:\Documents and Settings\Kristjan\Application Data\Opera\Opera\profile" "D:\$OEM$\$1\Install\Opera\profile" /I /E

So how should i add /exclude if i don't want cache4 and images form opera profile to be copied.

Link to comment
Share on other sites

Try this:

@ECHO OFF

:: Create an exclude file
>XCLUDE.TXT ECHO \cache4\
>>XCLUDE.TXT ECHO \images\

:: Copy the files and directories
XCOPY "%APPDATA%\OPERA\OPERA\PROFILE" "D:\$OEM$\$1\Install\Opera\profile" /EIQHKOY/EXCLUDE:XCLUDE.TXT

:: Delete the exclude file
DEL XCLUDE.TXT

GOTO :EOF

<Edit>

Just as a side note, since you are using the $Docs structure, you will probably not want the /O switch.

i.e. /EIQHKY/EXCLUDE:XCLUDE.TXT

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Just a thought......

If you don't want to copy a certain subdirectory but you DO want to keep it, you could simply move it to a different location, then do the xcopy and then move it back,,,all within the same batch file.

Or, you could even just let xcopy duplicate the whole tree structure and then delete the info you don't want....still from within the same batch file.

Sometimes when I want to do something but I don't know exactly how to do it directly, I develope a "Work Around". This is one of them cases.

I love XCopy, but it does have a few limitations.

Good Luck,

Andromeda43 B)

Link to comment
Share on other sites

Use the best file copy app MS ever made, Robocopy

I copy my Firefox Dir as a test here going to C:\Test not adding bookmarkbackups and chrome Folder

robocopy "%APPDATA%\Mozilla\Firefox" /MIR /V C:\Test /XD bookmarkbackups chrome /R:0
/MIR Means Mirror and the /V is Verify

I also added the /R:0 because I'm using Firefox right now and I don't want it to retry any, you can change that to a 1 or whatever, otherwise it tries like a million times

I'm just guessin since I don't have Opera on here

robocopy "%APPDATA%\OPERA\OPERA\PROFILE" /MIR /V "D:\$OEM$\$1\Install\Opera\profile" /XD cache4 images

Shutdown Opera and then you don't need the /R: <<retry

No Need for any extra BS there as you see :lol:

and all in one line

NOTE: /MIR will compare and delete what don't match REGARDLESS, read the readme

Edited by maxXPsoft
Link to comment
Share on other sites

maxXPsoft, as much as your information is good, and as much as I like robocopy, it's not really warranted on this occasion.

The Subject :
Xcopy in batch file

The question:
How should be the /exclude feature used. i can't find right syntax. Can anyone give me an example, how to exclude a dir.

I answered the question, hopefully well enough for a little thought and a little understanding. I used xcopy in a batch file with the /exclude feature usingthe questioners directories and a few comments.

If I were to ask, what registry setting do I need for…

someone will probably say 'use nlite'

If I asked, how do I fix … in Internet Explorer?

someone is guaranteed to say 'get Firefox'

If I asked, how do I do … in a batch file?

someone will likely say 'here's a vbscript'

There's nothing wrong with offering alternatives, but maybe 'in answer' as opposed to 'as answer' would be better.

Link to comment
Share on other sites

I have used robocopy for exact same thing with the exclude and knew how simple it is, I do know Xcopy problem's I've had so no more of that mess here if I can replace with the Robo.

Offering an alternative is part of what this Forum is all about, the discoveries of new techniques.

He can decide which, its up to him.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...