Aray
Aray

Reputation: 11

Count of rows through Batch file

All, need a help in a batch file script.

I have .txt file, the main purpose is to get the count of the file and if count is more than 1000 then create a .txt file otherwise finish the script.

I have a command in batch file as below;-

@echo on

cd C:\Windows\System32

type C:\Testfolder\Samplefile.txt| find "" /v /c

This gives me count of 1400. Now I need to include "When the count is >1000 then create a blank.txt file in a specific path otherwise dont do anything just complete the script.

Any help.

Thanks.

Upvotes: 0

Views: 145

Answers (1)

Squashman
Squashman

Reputation: 14290

You will need to use a FOR /F command to capture the output of the FIND command.

@echo off
FOR /F "delims=" %%G in ('type C:\Testfolder\Samplefile.txt^| find /v /c ""') do set count=%%G
IF %count% gtr 1000 type nul>"C:\some path\blankfile.txt"

Upvotes: 1

Related Questions