# XCOPY .bat file command



## Special2God (Oct 5, 2009)

```
@echo off
xcopy C:\important [E:\Backup] /EXCLUDE:"\Do Not Copy\"
pause
```
In the code example I bracketed the destination, is that correct? 
Can the source and destination both be different drives?
I'm not sure if the "EXCLUDE" command is properly written or if it needs brackets?

When I run it I get a question asking if "E:\Backup" is file or directory, to which I answer directory.
Thanks for any help! :smile:


----------



## TheOutcaste (Mar 19, 2009)

The destination should not be in brackets. The brackets in the help output indicate that that item is optional. If you don't specify a destination it will use the current folder as the destination. They can be different drives, and you can use UNC paths as well (\\Server\Share)

The exclude command must reference an existing plain text file. The file will contain the strings of what you want to exclude.
If you want to avoid being asked if the destination is a file or folder include a trailing slash.
As always, any path that contains spaces must be quoted.


```
@echo off
xcopy C:\important E:\Backup\ /EXCLUDE:C:\Stuff\list.txt
```
The file *C:\Stuff\list.txt* (can be anywhere and any name/extension, as long as it contains plain text) will have this line:

*\Do Not Copy\*

This will exclude any path that contains a _folder_ named *Do Not Copy*
Do not include quotes in the exclude strings

Exclude does a case insensitive string match to find things to exclude, searching the FQPN (fully qualified path name) for each file copied to see if it contains any of the strings in any of the specified exclude files. Wildcards are not allowed.

Since you didn't specify */E*, */S* or */T* to process subfolders, the exclude in this case will do nothing as it specifies a folder name, not a file.

Also, if you don't specify the /D switch, all files will be copied, even those that already exist. And it is possible to overwrite an existing file with an older copy if that switch is not used.


----------



## Special2God (Oct 5, 2009)

Ok, Thank you.
I think I understood that.
:grin:
(I'll leave the thread open if I need to ask something else.)


----------

