Batch to count the number of files

November 4, 2010 at 16:47:28
Specs: Windows XP, Quad 2.7 GHz

I have a batch file that looks for a particular string within htm files in a netword directory, which works well.

The guts of the batch is:

FINDSTR /S /M /C:\"dc_date_validfrom\" content=\"\" *.htm* >H:\BlankValidFromDates.txt

What I would like to do is either put a file count of the number of files found at the end of the output file, or insert line numbers in the output file before the file name that contains the search string.

Is there a quick/easy way to accomplish this?

Thank you in advance
Cheers Colleen

See More: Batch to count the number of files

Report •

November 5, 2010 at 02:24:20
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=
for /f "tokens=* delims= " %%a in ('findstr /s /m /c:if *.bat') do (
set /a N+=1
>> newfile echo.%%a
>> newfile echo.!N!

Life is too important to be taken seriously.


Report •

November 7, 2010 at 13:46:36
Hi Mechanix2Go,

Thank you for your reply. I have a couple of questions...

1. I assume I put this code in the existing batch file. Does it go at the top or the bottom?

2. Could you please explain what this does?

I am a relative newbie to batch files and I don't quite understand what this code is saying.


Report •

November 8, 2010 at 08:39:35
1. For most BATs it's not critical where it goes.

2. It counts by incrementing N. Puts names & count into newfile.

Life is too important to be taken seriously.


Report •
Related Solutions

Ask Question