Vasishta
Vasishta

Reputation: 23

Batch file - counting number of lines

I am using below BATCH script to count number of lines

Find /V /C "" < c:\Users\Admin\Desktop\123.txt >> lines.log

Is it possible to get info in a dialog / message box (info)

Upvotes: 0

Views: 1758

Answers (2)

SNR
SNR

Reputation: 762

To display a message box from cmd we will have to use a vbs and execute it from wscript instead of cscript. This will execute a windows application instead of a console application. Then, using .Echo() we will be able to make a message box pop up.

From the command line,

FOR /F "tokens=*" %%G  IN ('find /v /c "" ^< c:\Users\Admin\Desktop\123.txt') do ( 
set /a counter = %G 
)

echo >%temp%\msgbox.vbs Wscript.echo("Total count of lines: %counter%")

Wscript %Temp%\msgbox.vbs

Here counter will remain as an environment variable (set counter= to erase it). I suggest doing it from a batch file instead,

@echo off

setlocal EnableDelayedExpansion

FOR /F "tokens=*" %%G  IN ('find /v /c "" ^< c:\Users\Admin\Desktop\123.txt') do ( set /a counter = %%G )    

echo >%temp%\msgbox.vbs Wscript.echo("Total count of lines: !counter!")

Wscript %Temp%\msgbox.vbs

exit /B

Upvotes: 1

npocmaka
npocmaka

Reputation: 57252

Is this ok?

@echo off

set "file_to_check=./test.xml"

for /f "tokens=* delims=" %%# in ('Find /V /C "" ^< "%file_to_check%"') do (
    set "line_count=%%#"
)

::echo %line_count%

msg "%username%" "%line_count%"

or:

@echo off

set "file_to_check=./test.xml"

for /f "tokens=* delims=" %%# in ('Find /V /C "" ^< "%file_to_check%"') do (
    set "line_count=%%#"
)

::echo %line_count%

::msg "%username%" "%line_count%"

mshta "about:Lines of the %file_to_check% are <p> %line_count%"

Upvotes: 2

Related Questions