Count number of lines in file using batch

batchbatch filecommand linenotepad

I am using TrailerCount.bat file to count the number of lines in text file using below mentioned code

@Echo off
::set newline=^& echo.

SET FilePath=%1

Set /a _Lines=0

For /f %%j in ('Type %FilePath%^|Find "" /v /c ') Do Set /a _Lines=%%j

(
echo TRAILER %_Lines% 
)>>%FilePath%

Here when I am passing the txt file as a first input to batch file. After running it, its giving me Trailer as 8 in the last line of Text File which is correct if we open text file with "NOTEPAD". But using "Notepad++" it should be 11.

What changes i need to make to count empty lines,etc to get correct trailer count with respect to Notepad++???

Best Answer

The batch file is working correctly. find won't count a line unless it has the Windows LFCR* symbols on the line. You need to change the text file to have the LFCR symbols at the end of each line.

*LFCR is Line Feed, Carriage Return.

Related Question