Using Xcopy to backup - Can I exclude some directories?

R

Robin

I have made a batch file to back up Documents and Settings to a
partition on a second hard disk. The file is as follows:

xcopy c:\docume~1 i:\docume~1 /s /d

It works fine, but I would like to be able to exclude "Temp" and
"Temporary Internet Files" directories from the backup but have not
succeeded in getting the "/exclude" switch to do this.

Any ideas?

TIA.

Robin
 
R

Robin

so \temp\ didn't work?

You'll have to explain a bit more to me David. Best of all would be if
you could adapt my batch file for me. I tried \exclude: and it worked
OK with single files. But I ran into problems with wild cards and long
filenames. It looks like you have a simple solution I don't know
about.

Thanks

Robin
 
D

David Candy

I just typed
xcopy /?
and it said how to exclude a directory.

EG
c:\windows\file.txt

excluding \windows\ will exclude all files that have the phrase \windows\ in it, this will be every file under windows. It seems it works on fully qualified filename not directory and relative filenames. FQFN is the complete path. Relative is relative to the current directory.

If in windows \explorer.exe is a relative (with or without the first slash) but c:\windows\explorer.exe is fully qualified.

xcopy "c:\document and settings" "i:\documents and settings\" /s /d /EXCLUDE:c:\a.txt

a.txt contains

\temp\
\temporary internet files\
 
R

Robin

I just typed
xcopy /?
and it said how to exclude a directory.

EG
c:\windows\file.txt

excluding \windows\ will exclude all files that have the phrase \windows\ in it, this will be every file under windows. It seems it works on fully qualified filename not directory and relative filenames. FQFN is the complete path. Relative is relative to the current directory.

I didn't realise you could put your exclusions in a file.
If in windows \explorer.exe is a relative (with or without the first slash) but c:\windows\explorer.exe is fully qualified.

xcopy "c:\document and settings" "i:\documents and settings\" /s /d /EXCLUDE:c:\a.txt

a.txt contains

\temp\
\temporary internet files\


I tried your BAT file but it didn't work for me. But when I shortened
the folder names to docume~1 without the quotes and removed the final
back slash it did.

Thanks a lot.

Robin
 
R

Robin

I can see this now Dave. I didn't understand it properly the first
time I read it. (I'm not very used to working with the command line.

Thanks for helping me sort it out. I've added extra switches to copy
hidden files, copy attributes and not ask for confirmation and it now
does exactly what I want.

Robin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top