好吧,只是获取批处理的文件名最简单的方法就是使用%~n0。@echo %~n0将输出当前运行的批处理文件的名称(不带扩展名)(除非在调用的子程序中执行call)。help for在帮助的最后可以找到路径名称的这种“特殊”替换的完整列表:此外,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但是,要准确回答您的问题:使用:~start,length符号来完成子字符串:%var:~10,5%将从环境变量中的位置10提取5个字符%var%。注意:字符串的索引是零,所以第一个字符位于0,第二个字符位于1,等等。为了得到参数变量如子%0,%1等你给他们分配使用正常的环境变量set第一::: Does not work:@echo %1:~10,5:: Assign argument to local variable first:set var=%1@echo %var:~10,5%语法更强大:%var:~-7% 从中提取最后7个字符 %var%%var:~0,-4%将提取除最后四个之外的所有字符,这些字符也可以消除文件扩展名(假设在句点[ .] 之后有三个字符)。有关help set该语法的详细信息,请参阅