var blog = new ThoughtStream(me); RSS 2.0
 Wednesday, May 14, 2008

If you have a batch file that takes two parameters with quotes around them, and you concatenate them together, you get too many quotes.  For example, if you have “test.bat” file with this code in it:

Echo %1%2

And you run it like this:

Test.bat “C:\” “Program Files\”

You end up with this result

“C:\””Program Files\”

Which is not a valid folder. I’m trying to get this result:

“C:\Program Files\”

The problem is, I have to put quotes around both parameters on the command line, in case there are spaces in the folder names. The solution to this is to use a ~ character in the variable, like this:

Echo %~1%~2

Running that command in the test.bat file produces this result:

C:\Program Files\

More info and parsing capabilities can be found here:

DOS - String Manipulation

Wednesday, May 14, 2008 12:04:15 PM (Central Standard Time, UTC-06:00)  #    Comments [0]. Trackback 
Tags: General | Scripting

Navigation
About Me
View Derick Bailey's profile on LinkedIn

Send mail to the author(s) Contact Me
Archive
<May 2008>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Derick Bailey
Sign In
Statistics
Total Posts: 91
This Year: 91
This Month: 0
This Week: 0
Comments: 40
Themes
Pick a theme:
All Content © 2008, Derick Bailey
DasBlog theme 'Business' created by Christoph De Baene (delarou)