Minor batch file tricks
Just so I don’t forget how to do these things…
Remove quotes:
SET Line=”C:\Program Files\”
SET Line=%Line:”=%
echo %Line% — will output: C:\Program Files\
Remove a trailing backslash:
SET Line=C:\Windows\
IF “%Line:~-1%”==”\” SET Line=%Line:~0,-1%
echo %Line% — will output: C:\Windows
I was having an issue using a path that had a folder name with spaces in it inside a batch file i was calling with the paths quoted. I just used this trick to remove quotes and re add them around the paths i wanted. Thanks!
Use %~1 (et. al.) to remove surrounding quotes around batch file arguments. Type “call /?” for details.
Chuck
Where can I read the documentation on these types of things? i had no idea this was possible.
Watch the double quotes in the batch-files above: some of them got mangled from ” into “ and †(which cmd does not like), and some copy/paste operations keep those in your batch files.
–jeroen