怎么样批处理获取文件夹下面txt文件行数并添加到文件名后?

怎么样批处理获取文件夹下面txt文件行数并添加到文件名后?

方法一:

@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /a-d/b/s *.txt') do (
 for /f "tokens=3 delims=:" %%b in ('find /c /v "" "%%a"') do set n=%%b
 ren "%%a" "%%~na_!n: =!%%~xa"
)
pause

方法二:

@echo off & setlocal enabledelayedexpansion
%1(for /f "delims=" %%i in ('%~0 :^|sort') do ren %%i)& pause & exit /b
for /f "tokens=1,* delims= " %%i in ('find /c /v "" *.txt') do (
 set info=%%j
 set ln=!info:*:=!
 for /f "delims=" %%a in ("!ln!") do set fn=!info::%%a=!
 echo;"!fn!" "!fn:~,-4!!ln:~1!.txt"
)

批处理获取文件行数的方法

@echo off
for /f "tokens=2 delims=:" %%a in ('find /c /v "" data.txt')do set/a result=%%a+0
echo,%result%
pause

以上方法其实都大同小异,执行效率也差不多,小伙伴们需要的话自行选择吧