Xcopy returns an "Invalid number of parameters" error when setting an exception parameter

issuing:

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

works as expected. But:

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

returns an error:

Invalid number of parameters

What also happens when path names (containing spaces) are not enclosed in quotation marks. However, it is not. The paths (edited for readability) all fit correctly. The syntax (according to Product Documentation - Xcopy ) is also correct. Regarding the OS - Windows XP Professional x32 SP3.

Why does the second CMD return an error and how to solve it? I am not looking for alternatives to xcopy (robocopy, etc.).

+6
source share
2 answers

XCOPY is an old team returning to the days of DOS. It appears that the / EXCLUDE option has never been updated to support long file names. Ugh: - (

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

I believe that you have three possible solutions:

1) Use 8.3 short folder names in your path.

Of course, this will not work if your volume has short names.

2) Use the SUBST command to create a drive alias for your hard way.

 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 can be a problem if you do not know the free drive letter.

3) (my favorite) Just PUSHD follow the unpleasant path and execute 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 



For more details 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 .

+9
source

/EXCLUDE:file does not exclude the specified file. By xcopy reference to the command :

/exclude:FileName1[+[FileName2][+[FileName3](…)] Specifies a list of files. You must specify at least one file. Each file will contain search strings with each line in a separate line in the file. When any of the lines matches any part of the absolute path to the file to be copied, this file will be excluded from copying.

0
source

Source: https://habr.com/ru/post/988528/


All Articles