Count Files

I was wondering if anyone could help me with this problem:

Write a script called countFiles that takes two arguments, the initial directory and the number of levels and returns the count of all files (including directories) in the directories and subdirectories up to the number of levels.

*** This script must use loop(s), traverse directories, count files in a single directory, have an error detection, and determine that a file is a directory. (Use find if you would like)

I have findutils 4.2.2 and the following counts everything..

 find $1 -maxdepth $2 | wc -l 
1 Like

and if i dont have findutils 4.2.2, is there another way to solve this problem?

looks like homework.

yep it is homework,

i think i got it figured out for the most part:

counter=0

for file in * ; do
echo $file at $counter
let "counter+=1"
done

echo "COUNTER:$counter"