Bat 批处理 获取自己本身的文件名
2024-07-27 20:10:09    15    0    0
maker



@echo off
set name=%~n0
echo 当前文件名不包括扩展名为:%name%
pause


https://www.iteye.com/blog/ctwen-1172782 

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

https://stackoverflow.com/questions/15567809/batch-extract-path-and-filename-from-a-variable 

%~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


Pre: Bat 批处理 &、&&、|、||、>、>>符号

Next: IE10 在Windows 10/11系统中单独打开方法

15
Table of content