Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

How do I get the total number of lines of all the files in a directory ?

Hi,

How do I get the total number of lines of all the files in a directory ? - in DOS command prompt?

if there are 3 files , say a.txt, b.txt and c.txt each having 30 lines. Then I want to see the total 90. Do we have any command to do this?

Also how do I get the total no of lines of a specified file - in DOS command prompt?
0
GouthamAnand
Asked:
GouthamAnand
  • 3
  • 3
1 Solution
 
oBdACommented:
For a single file:
type "a.txt" | find /c /v ""

Open in new window

And here's a script to sum; just pass the files or folders as command line arguments (include in double quotes if the names contain spaces): Whatever.cmd a.txt b.txt c.txt or Whatever.cmd "S:\ome\folder\*.txt"
@echo off 
setlocal enabledelayedexpansion
set /a Total = 0
:ArgLoop
for /f "delims=" %%a in ('dir /b /a:-d "%~1"') do (
	for /f %%c in ('type "%%~a" ^| find /c /v ""') do set Lines=%%c
	echo [!Lines!] - '%%~fa'
	set /a Total += Lines
)
if not "%~2"=="" (
	shift
	goto ArgLoop
)
echo Total: %Total%

Open in new window

Edit: changed the script to support folders.
0
 
GouthamAnandAuthor Commented:
The number of files are lot many. So I cannot pass all the names as arguments. But I can pass the directory name.

Please suggest me now.
0
 
oBdACommented:
Sorry, I concentrated too much on your examples in my first attempt; I already changed the script to now support folders as well. Please copy it again from above.
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
GouthamAnandAuthor Commented:
Thanks a lot. But I have one more constraint - I want to include only certain types of files like *.txt or .sql to take into consideration in that directory.

Can you please suggest me now.
0
 
oBdACommented:
Just call it like in my example above: Whatever.cmd "S:\ome\folder\*.txt" or Whatever.cmd "S:\ome\folder\*.sql"
0
 
GouthamAnandAuthor Commented:
Thanks a lot.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now