Search code examples
windowsbatch-filexcopy

How do i use XCOPY with spaces in both paths, even with quotes?


I am trying to create a batch file that copies files from one path to another, using several xcopy commands. However, the batch script fails because Xcopy apparently has the wrong number of parameters.

I believe the reason is that it thinks the spaces in my folder paths are separating parameters- but I do not know why it is doing this because I have made sure that both the source and destination paths are surrounded with double-quotes.

for example, I run this command in my batch script:

c:/windows/system32/xcopy.exe "H:\some path with spaces\myfile.txt" "H:\some path with spaces\a_different_folder\myfile.txt" /Y

and it outputs this:

Invalid number of parameters

Can somebody please tell me what I'm doing wrong or if there is a workaround? I have also tried using the standard copy command, but that ends up saying the system cannot find the path specified (which isn't true, as my batch file is actually generated by a script that uses the paths of files that are guaranteed to exist)


Solution

  • as @Mark said:

    It is your path to xcopy. It is wrong. It is why you are getting the message. C: is a valid command. It will choose a valid command over fixing unix's paths