我怎样才能从脚本本身获得一个Windows .bat脚本的名称?

我有一个.bat文件。 我想以编程方式获取.bat文件的名称。 我怎样才能做到这一点?

这是我的最终目标

"..\lib\nant\nant.exe" -buildfile:nant.build {{pass in name of this file here}} pause 

尝试for /? 在命令行上。 该帮助显示了各种有用的文件名replace,例如:

 %~I - expands %I removing any surrounding quotes (") %~fI - expands %I to a fully qualified path name %~dI - expands %I to a drive letter only %~pI - expands %I to a path only %~nI - expands %I to a file name only %~xI - expands %I to a file extension only 

用0replaceI以获得batch file名称,并用1,2,3等replaceI以获取参数名称。

%0%variables将为您提供batch file的全限定path,包括其名称。 得到这个名字可能有更好的办法。