4

I have a batch script that triggers vlc for me on my network, the problem is it opens based on URLs in a browser. The browser automatically adds the %20 in place of a regular space, and I need to replace this with a regular space again in my batch script before sending the file path on to vlc.

Here is my code;

@echo off
set str=%1
set str=%str:~8%
set str=%str:%%20= %
START /D "C:\Program Files\VideoLAN\VLC\" vlc.exe %str%
pause

It is worth mentioning that this will run on a windows 7 and/or vista system.

Clorith
  • 459
  • 1
  • 6
  • 16
  • Ah... I see. Since '%' is the delimiter for the `%str%` variable, there is a problem to use string substition for its value, which also contains '%'. – Kurt Pfeifle Aug 12 '10 at 00:42
  • Why do you skip eight characters? You seem to have assumptions on the URL syntax you expect, but you are not writing what these are. Please add them to the question. – oberlies Mar 07 '18 at 13:47

1 Answers1

9
@echo off
setlocal enabledelayedexpansion
set str=%~1
set str=%str:~7%
set str=!str:%%20= !
"C:\Program Files\VideoLAN\VLC\vlc.exe" "%str%"
pause

Took the liberty of fixing some other things as well. If the script ran with quotes around the argument it always had a trailing " . Delayed expansion gives you a second set of variable delimiters here which avoids the trouble with the %. Furthermore, start isn't needed as far as I can see, unless you critically depend on VLC having its own directory as its startup path.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • Ooops! -- This answer wasn't visible for me when I wrote my comments to the question. -- **+1** though. -- I was myself struggling with `enabledelayedexpansion` but didnt get it to work here. – Kurt Pfeifle Aug 12 '10 at 01:12