1

It count number of line in all file but i need select the file with the largest number of lines.

for %%a in (*.*) do (
   for /f %%b in (' find "" /v /c ^< "%%a" ') do (
   echo %%a=%%b

)
)

Output:

test.txt=10
asdasd.txt=15
asdasd.txt=20

I need output:
asdasd.txt=20

only one file with the largest number of lines Pleas help. Thx

Proender
  • 43
  • 7

2 Answers2

0

First option, calling find for each file and then parsing output

@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%

Second option, calling find only one time and parsing output

@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%
MC ND
  • 69,615
  • 8
  • 84
  • 126
0

you need to set additional vars:

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!!