@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=*" %%a in ('dir /a-d/b *.txt') do (
set file=%%a
for /f "delims=: tokens=1,*" %%i in ('findstr /n .* !file!') do set "%%i=%%j" & set num=%%i
echo ===!file:~0,-5!===>!file!
for /l %%i in (1,1,!num!) do if defined %%i (>>!file! echo !%%i!) else (>>!file! echo.)
)
3742668版主的代码:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set file=test.txt
for /f "delims=: tokens=1,*" %%i in ('findstr /n . %file%') do set "%%i=%%j" & set num=%%i
echo 123456>%file%
for /l %%i in (1,1,%num%) do if defined %%i (>>%file% echo !%%i!) else (>>%file% echo.)