@echo off setlocal EnableExtensions if "%~1"=="" goto usage if not exist "%~1" ( echo File not found: %~1 exit /b 1 ) set "count=0" for /f "usebackq delims=" %%C in (`type "%~1" ^| find /c /v ""`) do set "count=%%C" echo Lines: %count% exit /b 0 :usage echo Usage: count_lines.bat file.txt exit /b 2