Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.).

like image 415
user4157124 Avatar asked Jun 04 '15 18:06

user4157124


People also ask

Does xcopy still work in Windows 10?

Xcopy Command AvailabilityThis command is available from within the Command Prompt in all Windows operating systems including Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows 98, etc.

Should I use copy or xcopy?

In many cases copying a single file is best done with the COPY command. When copying a single file with XCOPY, there is no option to indicate if the destination is a filename or a directory (with the filename defaulting to that of the source file).

What is the difference between robocopy and xcopy?

Robocopy is used to mirror or sync directories while Xcopy does nothing about that. Robocopy can check the destination directory and delete all the files no longer in the main tree rather than copy all the files from one directory to another. In addition, it won't copy the unchanged files to save your time.


1 Answers

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.

like image 158
dbenham Avatar answered Sep 21 '22 18:09

dbenham