Highlighted
New Contributor

# Robocopy doesn't work with folders given as arguments.

Hi!

I'm writing a .bat script to copy exactly one file between two harddrives.

First I write this:

SET A1=%1  <source>

SET A2=%2  <destination>

SET A3=%3  <file>

This works: (folders are hard-coded)

ROBOCOPY C:\test\ "D:\Folder with spaces\" %A3%

This does not work: (all arguments)

ROBOCOPY %A1% %A2% %A3%

When it fails, it can be of several reasons:

Robocopy cannot find the file.

Robocopy messes up on the folders, so the <source> ends at the first space in <destination>

The following tweaks does not either work:

Replacing SET A1=%1 with SET A1="%~1" , (along with the rest of the arguments)

Omitting spaces, so %A1% %A2% %A3% becomes %A1%%A2%%A3% .

Do you have any suggestions to what I can do to get Robocopy to work with all the arguments, with no hard-coding?

2 Replies
Highlighted

# Re: Robocopy doesn't work with folders given as arguments.

Hi,
Which Windows 10 build are you using?
Highlighted

# Re: Robocopy doesn't work with folders given as arguments.

I'm sorry I didn't state this in the original post.

I'm using Windows 8.1 Pro.

I couldn't find a separate community specifically for 8.1, so I went for 10.