嘿 stackoverflow 社区,
我尝试在 Sublime Text 3 中为 xampp/htdocs 目录中的 .html 文件设置构建系统。
因此我需要替换部分文件路径并添加
“http://localhost/”
开头,然后在浏览器中调用它。欢迎提出任何建议。
到目前为止我从其他线程中发现了什么:
SETLOCAL ENABLEDELAYEDEXPANSION
-- represtened by the $file variable in Sublimetext 3 - filepath would look like "${file}" --
SET filepath="C:\xampp\htdocs\test.html"
SET searchstring="C:\xampp\htdocs\"
SET replacestring="http://localhost/"
SET modifiedpath=%searchstring%=%replacestring%!
-- not sure about this one but it should work as it does for hardcoded sites --
"C:\Program Files\Opera\launcher.exe" !modifiedpath!
我从这些命令中得到的结果只是我输入的在浏览器中打开的第一个文件路径。
我做错了什么?我找不到任何有关使用 cmd 操作路径的主题。 系统 = W7/32 位和 W8/64 位结果相同
提前致谢, 彼得
最佳答案
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
:: -- represtened by the $file variable in Sublimetext 3 - filepath would look like "${file}" --
SET "filepath=C:\xampp\htdocs\test.html"
SET "searchstring=C:\xampp\htdocs\"
SET "replacestring=http://localhost/"
CALL SET "modifiedpath=%%filepath:%searchstring%=%replacestring%%%"
:: Belt-and-braces
SET "modifiedpath=%modifiedpath:\=/%"
:: -- not sure about this one but it should work as it does for hardcoded sites --
ECHO "C:\Program Files\Opera\launcher.exe" "%modifiedpath%"
GOTO :EOF
这应该可以工作 - 实际上这里不需要 enabledelayeexpansion
。
不确定 Opera - 可执行文件名称周围的引号是必需的,但参数可能是,也可能不是。由于我还没有安装它,所以我只是对其进行了 ECHO
编辑 - 您需要删除 ECHO
才能使其正常工作。事实上,CMD
将仅显示一个应调用 Opera 的命令行。
关于batch-file - 如何使用cmd替换部分路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21199316/