Dealing with quotes in Windows batch scripts

GetFree picture GetFree · Feb 11, 2009 · Viewed 97.4k times · Source

In a Windows batch file, when you do the following:

set myvar="c:\my music & videos"

the variable myvar is stored with the quotes included. Honestly I find that very stupid. The quotes are just to tell where the string begins and ends, not to be stored as part of the value itself.
How can I prevent this from happening?

Thanks.

Answer

RuskoGuyachev picture RuskoGuyachev · Dec 20, 2011
set "myvar=c:\my music & videos"

Notice the quotes start before myvar. It's actually that simple. Side note: myvar can't be echoed afterwards unless it's wrapped in quotes because & will be read as a command separator, but it'll still work as a path.

http://ss64.com/nt/set.html under "Variable names can include Spaces"