如何在 Windows 中获取批处理脚本的路径? [英] How to get the path of the batch script in Windows?

查看:27
本文介绍了如何在 Windows 中获取批处理脚本的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 %0 包含批处理脚本的完整路径,例如c:path omyfileabc.bat

I know that %0 contains the full path of the batch script, e.g. c:path omyfileabc.bat

我希望 path 等于 c:path omyfile

我怎么能做到这一点?

推荐答案

%~dp0 将是目录.这里有一些关于所有路径修饰符的文档.有趣的东西:-)

%~dp0 will be the directory. Here's some documentation on all of the path modifiers. Fun stuff :-)

要删除最后的反斜杠,您可以使用 :n,m 子字符串语法,如下所示:

To remove the final backslash, you can use the :n,m substring syntax, like so:

SET mypath=%~dp0
echo %mypath:~0,-1%

不幸的是,我认为没有办法将 %0 语法与 :~n,m 语法结合起来.

I don't believe there's a way to combine the %0 syntax with the :~n,m syntax, unfortunately.

这篇关于如何在 Windows 中获取批处理脚本的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆