bat中直接使用文件名,可用下面
set name=%~n0
用到了下面链接的第二个答案
https://zhidao.baidu.com/question/556178601.html
其中~n0的意思:
%0 批处理自己
%1 第1个参数
%2 第2个参数
依次到%9
对于变量%0~%9及for里使用的%i这样的变量,可以有以下的语法:
https://stackoverflow.com/questions/15567809/batch-extract-path-and-filename-from-a-variable
in HELP CALL
or HELP FOR
you may find more detailed information:
%~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
@ECHO OFF
SETLOCAL
set file="C:\Users\ l72rugschiri\Desktop\fs.cfg"
FOR /F "delims=" %%i IN ("%file%") DO (
ECHO filedrive=%%~di
ECHO filepath=%%~pi
ECHO filename=%%~ni
ECHO fileextension=%%~xi
)