本帖最后由 yhcfsr 于 2018-8-29 13:29 编辑
- @echo off
- ::设置文本路径
- set "Text=a.txt"
- ::========主程序区========
- call :get_index "%~n0" index
- call :get_lines %index% line
- ::设置变量m
- set "m=%line%"
- pause&exit
-
- ::========子程序区========
- :get_index 获取脚本序号
- setlocal
- set "ScriptName=%~1"
- set "num="
- :lp
- set "n=%ScriptName:~-1%"
- if "%n%" neq "(" (
- if "%n%" neq ")" set "num=%n%%num%"
- set "ScriptName=%ScriptName:~,-1%"
- goto:lp
- )
- endlocal&set "%2=%num%"&goto:eof
-
- :get_lines 获取序号对应行
- setlocal
- set/a "n=%~1 - 1"
- for /f "skip=%n% delims=" %%a in ('type "%Text%"') do endlocal&set "%2=%%a"&goto:eof
复制代码 获取序号用了比较烦琐的方法,主要是考虑到如果是这样的文件名:ab(cd)efg(1).bat |