O più semplicemente:
codice:
@echo off
if "%*"=="" (
    echo Missing filename parameter.
    goto :syntax
)
if "%1"=="/?" goto :syntax
if "%1"=="-?" goto :syntax 
if not exist %* (
    echo The specified file name is not valid.
    goto :eof
)
set linescount=0
for /f "usebackq" %%D in (`type %*`) do (
    set /a linescount+=1
)
echo %1 contains %linescount% rows.
goto :eof
:syntax
echo Syntax:
echo COUNTLINES filename
echo    filename    The name of the file whose lines will be counted.
goto :eof
.