Home

Robocopy doesn't work with folders given as arguments.

%3CLINGO-SUB%20id%3D%22lingo-sub-1181179%22%20slang%3D%22en-US%22%3ERobocopy%20doesn't%20work%20with%20folders%20given%20as%20arguments.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1181179%22%20slang%3D%22en-US%22%3E%3CP%3EHi!%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFirst%20I%20write%20this%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3ESET%20A1%3D%251%26nbsp%3B%20%3C%2FSTRONG%3E%3CSOURCE%3E%3C%2FSOURCE%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3ESET%20A2%3D%252%26nbsp%3B%20%3C%2FSTRONG%3E%3CDESTINATION%3E%3C%2FDESTINATION%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3ESET%20A3%3D%253%26nbsp%3B%20%3C%2FSTRONG%3E%3CFILE%3E%3C%2FFILE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20works%3A%20(folders%20are%20hard-coded)%3C%2FP%3E%3CP%3E%3CSTRONG%3EROBOCOPY%20C%3A%5Ctest%20%22D%3A%5CFolder%20with%20spaces%22%20%25A3%25%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20does%20not%20work%3A%20(all%20arguments)%3C%2FP%3E%3CP%3E%3CSTRONG%3EROBOCOPY%20%25A1%25%20%25A2%25%20%25A3%25%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20it%20fails%2C%20it%20can%20be%20of%20several%20reasons%3A%3C%2FP%3E%3CP%3ERobocopy%20cannot%20find%20the%20file.%3C%2FP%3E%3CP%3ERobocopy%20messes%20up%20on%20the%20folders%2C%20so%20the%20%3CSOURCE%3E%20ends%20at%20the%20first%20space%20in%20%3CDESTINATION%3E%3C%2FDESTINATION%3E%3C%2FSOURCE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20following%20tweaks%20does%20not%20either%20work%3A%3C%2FP%3E%3CP%3EReplacing%26nbsp%3B%3CSTRONG%3ESET%20A1%3D%251%26nbsp%3B%3C%2FSTRONG%3Ewith%26nbsp%3B%3CSTRONG%3ESET%20A1%3D%22%25~1%22%3C%2FSTRONG%3E%20%2C%20(along%20with%20the%20rest%20of%20the%20arguments)%3C%2FP%3E%3CP%3EOmitting%20spaces%2C%20so%26nbsp%3B%3CSTRONG%3E%25A1%25%20%25A2%25%20%25A3%25%26nbsp%3B%3C%2FSTRONG%3Ebecomes%26nbsp%3B%3CSTRONG%3E%25A1%25%25A2%25%25A3%25%26nbsp%3B%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20you%20have%20any%20suggestions%20to%20what%20I%20can%20do%20to%20get%20Robocopy%20to%20work%20with%20all%20the%20arguments%2C%20with%20no%20hard-coding%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1181179%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Ebat%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFolders%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Erobocopy%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1182723%22%20slang%3D%22en-US%22%3ERe%3A%20Robocopy%20doesn't%20work%20with%20folders%20given%20as%20arguments.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1182723%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3EWhich%20Windows%2010%20build%20are%20you%20using%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1183008%22%20slang%3D%22en-US%22%3ERe%3A%20Robocopy%20doesn't%20work%20with%20folders%20given%20as%20arguments.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1183008%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F310193%22%20target%3D%22_blank%22%3E%40HotCakeX%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20sorry%20I%20didn't%20state%20this%20in%20the%20original%20post.%3C%2FP%3E%3CP%3EI'm%20using%20Windows%208.1%20Pro.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20couldn't%20find%20a%20separate%20community%20specifically%20for%208.1%2C%20so%20I%20went%20for%2010.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

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
Hi,
Which Windows 10 build are you using?
Highlighted

@HotCakeX 

 

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.

Related Conversations