Count of files in directories

Hi,

I have a requirement to find out the count of files in directories. I can do this very well by goind to each directory and then ls -lrt | wc -l. But I need to do it for hundreds of directories/sub-directories.
I tried with this -
for i in `ls -F | grep '/$'`; do `echo "$i"`| ls -lrt `echo "$i"` | wc -l; done;
but its not working. To execute this and I need to go to a directory but it wont give the count of files in sub-directories.
Please suggest.

Thanks in advance.

Slightly modified your solutions. Try this out.

#! /usr/bin/sh

for i in `ls -F | grep '/$'`
 do
echo "$i"
a=`ls -lrt $i | wc -l`
let a=a-1
echo $a;
let total=total+$a
done;

echo "Total Number of Files $total";

Another approach - using "find". Should work for any number of files.
This is a skeleton script. You could influence the processing order or output order by inserting sort statements.
If you have links, you may need a "-follow" switch to "find".

#!/bin/ksh
find /start_dir/ -type d -print | while read SUBDIR
do
        COUNTER=`find "${SUBDIR}" ! -type d -print|wc -l`
        echo "${SUBDIR} : ${COUNTER}"
done