我 6 楼的代码有个缺点:批处理文件名不能包含有空格
改进可以包含空格:
@echo off
for /f "tokens=1,2* delims=:" %%i in ('findstr /nv "`" "%~nx0"') do set /a N=%%i-1
for /f "skip=%N% delims=" %%i in ('type "%~nx0"') do (
for %%n in (%%i) do set /a %%n+=1)
set /a :+=1
echo.&echo. 第 %:% 运行。&echo.
set/p=: <nul>>"%~nx0"
pause
exit
文件名不能包含有特殊符号!
编好后的的批处理必须在最后一行换行为空行
XP SP2测试通过
Last edited by zh159 on 2007-1-7 at 12:15 AM ]
There is a shortcoming in the code on my 6th floor: the batch file name cannot contain spaces.
Improvement to allow spaces:
@echo off
for /f "tokens=1,2* delims=:" %%i in ('findstr /nv "`" "%~nx0"') do set /a N=%%i-1
for /f "skip=%N% delims=" %%i in ('type "%~nx0"') do (
for %%n in (%%i) do set /a %%n+=1)
set /a :+=1
echo.&echo. The %:% run. &echo.
set/p=: <nul>>"%~nx0"
pause
exit
The file name cannot contain special symbols!
The compiled batch file must have an empty line at the last line for a newline
Test passed on XP SP2
Last edited by zh159 on 2007-1-7 at 12:15 AM ]