xcopy returns error “Invalid number of parameters” when exclude parameter is set

XCOPY is an old command harking back to the days of DOS. It looks like the /EXCLUDE option was never updated to support long file names. Ugh 🙁

If you remove the quotes, then the text after the space is interpreted as an additional parameter, and you get the “Invalid number of parameters” error. If you keep the quotes, then it treats the quotes as part of the path, and reports it cannot find the file.

I believe you have three possible solutions:

1) Use the short 8.3 folder names in your path.

Of course this cannot work if your volume has short names disabled.

2) Use the SUBST command to create a drive alias for your troublesome path.

subst Q: "Y:\path with spaces"
xcopy X:\ "Y:\...\bin\9876543210\" /c /g /d /i /e /r /h /y /exclude:Q:exclude.txt
subst Q: /d

This could be a problem if you don’t know a drive letter that is free.

3) (my favorite) Simply PUSHD do the troublesome path and run the command from there 🙂

pushd "Y:\path with spaces"
xcopy X:\ "Y:\...\bin\9876543210\" /c /g /d /i /e /r /h /y /exclude:exclude.txt
popd



See https://sevenx7x.wordpress.com/2009/01/02/xcopy-with-exclude-option-shows-cant-read-file/ and http://forums.majorgeeks.com/showthread.php?t=54300 for more information.

Leave a Comment