0

I am new to batch files and created a batch file to back up a networked drive at work to my OneDrive folder so that I could access work files at home. Since then they have decided to install Office365 on everyones computer at work. Now instead of OneDrives folder just being called 'OneDrive' it is now called 'OneDrive - G&S Foods, Inc' My very simple batch file worked great until OneDrives name was changed. I cannot change the name back to just OneDrive, so I am trying to work around in my batch file. It seems the special characters are giving me an issue though, expecially the &. I now get the following error

Invalid number of parameters '&' is not recognized as an internal or external command, operable program or batch file.

My Question is: What is the best way to work around the special characters issue?

Here are my current script lines:

@echo off xcopy j:\Brandon C:\Users\bweibley\OneDrive - G&S Foods, Inc /m /e /y xcopy J:\Joe's Folder\ChocScheduleBackUps C:\Users\bweibley\OneDrive - G&S Foods, Inc\ChocScheduleBackUps /m /e /y 
2
  • Thats barely a programming related question. Use double quotes for every path/file name containing spaces or otherwise poisenous characters. Commented Jan 18, 2017 at 15:31
  • 1
    Best practice is to always enclose your file paths in double quotes regardless of needing them or not. Then you never need to worry about it. Commented Jan 18, 2017 at 15:35

2 Answers 2

1

Do so by enclosing the whole path in double quotes:

xcopy "j:\Brandon" "C:\Users\bweibley\OneDrive - G&S Foods, Inc" /m /e /y 

You should already use double quotes if only a space is in there. So for your second line:

xcopy "J:\Joe's Folder\ChocScheduleBackUps" "C:\Users\bweibley\OneDrive - G&S Foods, Inc\ChocScheduleBackUps" /m /e /y 
Sign up to request clarification or add additional context in comments.

Comments

1

Try:

xcopy "j:\Brandon" "C:\Users\bweibley\OneDrive - G&S Foods, Inc" /m /e /y xcopy "J:\Joe's Folder\ChocScheduleBackUps" "C:\Users\bweibley\OneDrive - G&S Foods, Inc\ChocScheduleBackUps" /m /e /y 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.