Link to home
Start Free TrialLog in
Avatar of ewang1205
ewang1205

asked on

count number of files using dos command and then email to me the count

I like to the count number of files using dos command and then email to me the count.  Not sure if dos can send email.  So, count the number of files and store the count in a file.  Thanks.
Avatar of ReneGe
ReneGe
Flag of Canada image

Here you go

 
@echo off

REM DO NET FORGET TO CUSTOMIZE THIS SCRIPT.

SET ThePath=C:\Temp

for /f %%a in ('dir /s %ThePath% ^| FINDSTR -i "file"') DO SET FileCount=%%a

echo Total Files=%FileCount%


:SendEmail
REM YOU CAN DOWNLOAD BLAT EMAIL COMMAND LINE UTILITY AT
REM http://sourceforge.net/projects/blat/files/Blat%20Full%20Version/Blat%20v2.6.2/blat262.full.zip/download

SET Emailer=blat.exe
SET EmailTo=user@emailaddress.com
SET EmailFrom=sysadmin@emailaddress.com
SET EmailSubject=File Count for %ThePath%
SET EmailServer=smtp.server.com
SET EmailBody=Total Files for %ThePath% is:%FileCount%

"%Emailer%" -body "%EmailBody%" -to "%EmailTo%" -f "%EmailFrom%" -s "%EmailSubject% %time%" -server "%EmailServer%" -debug -timestamp -log "Email.log" >NUL

Open in new window

SOLUTION
Avatar of athar_anis
athar_anis
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Result:
For arround 1 300 000 files on a RAID 0 Dual SSD drive

dir /a-d /s /b "%ThePath%" ^|find /c /v "" : TOOK: 1min25secs
dir /s %ThePath% ^| FINDSTR -i "file" : TOOK: 1h30mins

I did not test the precision of the results I'll let this to be tested by one of you.

So my last batch file, and including "athar_anis" find command line seems to be the best solution.

Cheers,
Rene

To add to my previous statment:
I did not test the precision of the results I'll let this to be tested by one of you.

MEANING:
I did not test the precision of the file count results I'll let this to be tested by one of you.

Avatar of ewang1205
ewang1205

ASKER

Great job! Outstanding work!
As they were not exactly the same:

dir /a-d /s /b "%ThePath%" ^|find /c /v "" : TOOK:1min25secs  FILE COUNT:1319444
dir /s %ThePath% ^| FINDSTR -i "file" : TOOK:1h30mins  FILE COUNT:1319960

Thinking about it, I'd say that the one that has the highest file count wins, but it takes longer.  Depending misc confige and NTFS security settings... both command lines may give you the same file count results.

Have fun!
Thanks ewang1205

Cheers,
Rene