批处理文件-计算行数

时间:2019-09-27 07:08:26

标签: batch-file

我正在使用下面的BATCH脚本来计算行数

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

是否可以在对话框/消息框(信息)中获取信息

2 个答案:

答案 0 :(得分:1)

可以吗?

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

或:

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

答案 1 :(得分:1)

要显示来自cmd的消息框,我们将不得不使用vbs并从wscript而不是cscript执行它。这将执行Windows应用程序而不是控制台应用程序。然后,使用.Echo(),我们将弹出一个消息框。

在命令行中,

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

此处counter将保留为环境变量(set counter=将其删除)。我建议从批处理文件代替

@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