windows cmd 打开相对路径下的网页文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013614126/article/details/83029389

需求

给项目用 Sphix 做了文档,但是最终编译出来的文档入口 index.html 需要进入很多层文件夹后才能找到,如果创建快捷方式,只能在自己的电脑上有用,到其他人电脑上相应的路径就不对了,而 Windows 目前并不能在快捷方式中写相对路径。

所以想到用命令行来打开相应的文件以方便打开文档进行阅读。

环境

  • Microsoft Windows 10 企业版 10.0.14393 版本 14393

实现

将以下代码保存为一个 run.bat 文件

chcp 65001
start "" ".\客户端设计\_build\html\index.html"

也就是使用 start "" "目标文件路径"的形式。注意目标文件路径要写成与 run.bat 相对的路径。

这样双击 run.bat 就可以达到实际双击 index.html 这个文件的效果了。而且支持路径中有中文。

参考资料

  1. windows 控制台cmd乱码的解决办法
  2. Relative shortcuts for Windows
  3. Using relative paths for Windows shortcuts
  4. Echo UTF-8 characters in windows batch
  5. How to open an HTML file from a batch file in default browser with a specific destination anchor?
  6. How to easily open files and URLs from the command line
  7. Making a Windows shortcut start relative to where the folder is?

猜你喜欢

转载自blog.csdn.net/u013614126/article/details/83029389
今日推荐