And if I understand it correctly, the syntax (i.e order of switches) is still correct except for the specification of the excluded files.
But why would I need to put \windows\ in a separate text file? I don't even understand what you mean by this.
the /EXCLUDE switch is documented in /?- it specifies a list of files containing strings. The rest of the paragraph describes the format of the text file as well as how the strings within the file will be parsed and compared with each filename. eg. "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." is referring not to the strings provided on the command line, but rather how strings should appear in the text files specified in the /exclude switch.
Reading the xcopy help tells me that it is actually possible to run:
xcopy c: e: /s /exclude \windows\
Because windows already is a root directory.
/exclude is documented as accepting text files that contain strings, not the strings themselves. using the above will likely give you a message of the sort
Can't read file, \windows\
0 File(s) copied
And windows sucks when it comes to that kind of simple and good features.
It has nothing to do with Windows itself. When an application opens a file, it is supposed to specify a "Share mode"; that is, how other programs can use that file while it's open. (whether other files can read, write, or delete it are separate, so a program could lock file writes but allow other programs to read the file while it has it open). If the program opens a file but doesn't specify a share mode, Windows decides that caution is the better part of valour and prevents Reads, Writes, and Deletes, effectively locking the file until the application closes it.
Another interesting point: some people occasionally have issues where Explorer.exe keeps a file open. This is not, however, Windows Explorer that is keeping the file open, but rather "Shell Extensions" which explorer loads. The result is that the shell extension, usually installed as part of a third party program, will open the file, but not specify a share mode, so the file get's locked; and then it never closes it. The result is that Explorer (which is the associated process) get's blamed. It's not really a bug in explorer, but a bug in an extension.
When I discovered this I naively thought that it also could copy itself
It works for me:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Windows\system32>xcopy xcopy.exe C:\xcopy.exe
Does C:\xcopy.exe specify a file name
or directory name on the target
(F = file, D = directory)? F
C:xcopy.exe
1 File(s) copied
C:\Windows\system32>