它计算所有文件中的行数,但我需要选择行数最多的文件。
for %%a in (*.*) do (
for /f %%b in (' find "" /v /c ^< "%%a" ') do (
echo %%a=%%b
)
)
输出:
的test.txt = 10
asdasd.txt = 15
asdasd.txt = 20
我需要输出:
asdasd.txt = 20
只有一个行数最多的文件 请求帮助。 THX
答案 0 :(得分:0)
第一个选项,为每个文件调用find
,然后解析输出
@echo off
setlocal enableextensions enabledelayedexpansion
set "maxLines=0"
set "maxFile="
for %%a in (*.txt) do (
for /f %%b in ('^<"%%a" find /c /v ""') do if %%b gtr !maxLines! (
set "maxLines=%%b"
set "maxFile=%%a"
)
)
echo %maxFile%=%maxLines%
第二个选项,只调用find
一次并解析输出
@echo off
setlocal enableextensions enabledelayedexpansion
set "maxLines=0"
set "maxFile="
for /f "tokens=* delims=- " %%a in ('find /c /v "" *.txt '
) do for /f "tokens=1,2 delims=:" %%b in ("%%a"
) do if %%c gtr !maxLines! (
for %%d in (%%c) do set "maxLines=%%d"
set "maxFile=%%b"
)
echo %maxFile%=%maxLines%
答案 1 :(得分:0)
您需要设置其他变量:
echo off
setlocal enableextensions enabledelayedexpansion
set /A counter=0
for /f "tokens=1,2* delims=-:" %%a in ('find /c /v "" *.*') do (
if !counter! LSS %%b (
set /A counter=%%b
set bezieher=%%~nxa)
)
)
echo %bezieher%=%counter%
pause
Rem Respect to the scriptwriter "MC ND" above!!