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

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

问题描述

我知道 0%包含批处理脚本,例如完整路径 C:\\路径\\为\\我\\文件\\的abc.txt

I know that %0 contains the full path of the batch script, e.g. c:\path\to\my\file\abc.txt

路径等于 C:\\路径\\为\\我\\文件

我怎么能做到这一点?

推荐答案

%〜DP0 将是目录。 <一href=\"http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true\">Here's在所有路径的一些文档修饰符。有趣的东西: - )

%~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天全站免登陆