@echo off set name=%~n0 echo 当前文件名不包括扩展名为:%name% pause
bat文件:
@echo off echo 当前盘符:%~d0 echo 当前盘符和路径:%~dp0 echo 当前批处理全路径:%~f0 echo 当前盘符和路径的短文件名格式:%~sdp0 echo 当前CMD默认目录:%cd% echo 目录中有空格也可以加入""避免找不到路径 echo 当前盘符:"%~d0" echo 当前盘符和路径:"%~dp0" echo 当前批处理全路径:"%~f0" echo 当前盘符和路径的短文件名格式:"%~sdp0" echo 当前CMD默认目录:"%cd%" pause
Batch Extract path and filename from a variable - Stack Overflow
%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file