15

Issuing:

xcopy X:\ "Y:\...\bin\9876543210\" /c /g /d /i /e /r /h /y

works as expected. However:

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

returns error:

Invalid number of parameters

Which also occurs when path names (containing spaces) are not enclosed by quotation marks. This however, is not the case. Paths (edited for readability) all correspond correctly. Syntax (as per Product Documentation - Xcopy) is also correct. Concerning OS is Windows XP Professional x32 SP3.

Why is second cmd returning error and how is it to be solved? I am not looking for alternatives to xcopy (robocopy etc.).

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
user4157124
  • 2,809
  • 13
  • 27
  • 42

3 Answers3

20

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.

dbenham
  • 127,446
  • 28
  • 251
  • 390
0

/EXCLUDE:file switch will not exclude the file specified. As per xcopy command reference:

/exclude:FileName1[+[FileName2][+[FileName3](…)] Specifies a list of files. At least one file must be specified. Each file will contain search strings with each string on a separate line in the file. 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.

JosefZ
  • 28,460
  • 5
  • 44
  • 83
  • 3
    I believe the OP understands that already. The problem is the required path contains spaces, and the XCOPY /EXCLUDE option does not work if you include quotes around the exclude file path. – dbenham Jun 04 '15 at 19:55
0

It took me some time to get this right as well (I had the same errors), but ultimately, this format worked for me. As with all things DOS, absolute precision is critical, so feel free to copy and paste the below.

xcopy /t /e "C:\Users\username\Your Folder" "C:\Users\user\Your Folder"
Fedor
  • 17,146
  • 13
  • 40
  • 131
DAKNYC
  • 1