Question

Say a directory contains the following files:(no sub directories)

AError.csv - 1 line

BError.csv - 2 lines

CError.csv - 10 lines

DError.csv - 10 lines

ASuccess.csv - 1000 lines

then output should be: all files names where the file name contains error and has more than one lines.

For above output should be:

BError.csv CError.csv DError.csv

I have set number of lines in a variable

@echo off

cls

setlocal EnableDelayedExpansion

set "cmd=findstr /R /N "^^" *.csv | find /C ":""


for /f %%a in ('!cmd!') do set number=%%a

echo %number%
Was it helpful?

Solution

@echo off

    setlocal enableextensions enabledelayedexpansion
    set "_list="
    for %%f in ("*error*.csv") do (
        for /F %%l in ('type "%%~ff" ^| find /c /v "" ') do (
            if %%l gtr 1 set "_list=!_list! %%~nxf"
        )
    )
    echo %_list%
    endlocal

For each file which meets the naming condition, count the number of lines and, if greater than 1 concat to variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top