Windows批处理脚本URL解码 [英] Windows batch script url decoding
问题描述
我有一个批处理脚本,可在我的网络上为我触发vlc,问题是它基于浏览器中的URL打开. 浏览器会自动添加%20代替常规空间,在将文件路径发送到vlc之前,我需要在批处理脚本中再次将其替换为常规空间.
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.
这是我的代码;
@echo off
set str=%1
set str=%str:~8%
set str=%str:%%20= %
START /D "C:\Program Files\VideoLAN\VLC\" vlc.exe %str%
pause
值得一提的是,它将在Windows 7和/或Vista系统上运行.
It is worth mentioning that this will run on a windows 7 and/or vista system.
推荐答案
@echo off
setlocal enabledelayedexpansion
set str=%~1
set str=%str:~7%
set str=!str:%%20= !
"C:\Program Files\VideoLAN\VLC\vlc.exe" "%str%"
pause
也可以自由修复其他问题.如果脚本在参数周围使用引号引起来,则该脚本始终带有尾随"
.延迟扩展在此处为您提供了第二组变量定界符,从而避免了%
带来的麻烦.此外,据我所知,不需要start
,除非您严格依赖VLC将其自己的目录作为其启动路径.
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.
这篇关于Windows批处理脚本URL解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!