你可以用一些for
诡计做到这一点:
@setlocal enableextensions enabledelayedexpansion
@echo off
echo %0
for %%f in (%0) do set basename=%%~nf
echo Will run \arbitrary-path\%basename%
endlocal
的%%~nf
给你%%f
变量的名称,没有路径或扩展。如果你喜欢的东西运行:
C:\Users\Pax\qq.cmd
,你会看到类似这样的:
c:\Users\Pax\qq.cmd
Will run \arbitrary-path\qq
你可以看到所有的其他有用的扩展,如果你键入for /?
到命令行窗口:
%~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
%~sI - expanded path contains short names
only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in
the PATH environment variable and
expands %I to the fully qualified
name of the first one found. If the
environment variable name is not
defined or the file is not found by
the search, then this modifier
expands to the empty string
修饰符可以结合得到复合结果:
%~dpI - expands %I to a drive letter and
path only
%~nxI - expands %I to a file name and
extension only
%~fsI - expands %I to a full path name with
short names only
%~dp$PATH:I - searches the directories listed in
the PATH environment variable for
%I and expands to the drive letter
and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
谢谢。 此代码: '@回响 @setlocal ENABLEEXTENSIONS enabledelayedexpansion 为%% F IN(%0)做设定基名= %%〜NF 组UsPr =%USERPROFILE% 拷贝%0 “%UsPr%” 开始“%UsPr%\%basename%.bat”' 如果这是在禁用CMD的计算机上使用的,当第二个批处理文件使用start命令打开时会出错说cmd被禁用,我怎么能解决这个问题?还有,如何才能停止打开自己无限的时间直到你的电脑崩溃/死机? – Neb9 2014-11-24 06:52:23
@ Neb9,如果'cmd'被禁用,所有投注都关闭。你无法确定地运行任何命令脚本。而且,如果您想停止无限回归,只需添加一个检查以确保'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' – paxdiablo 2014-11-24 07:06:39
对不起,我没有经验的批次,我将如何添加你描述的支票?如果禁用了cmd,批处理将生效,但不能使用start命令从批处理文件启动任何批处理文件。 – Neb9 2014-11-24 07:26:03