Sunday, July 20, 2014

Counting the files in all sub drectories of a folder

Assumptions:
Given a directory; it has n subdirectories and does not have any files. The subdirectories jsut have files and no folders.
You want to count all the files in the n sub directories.

here's a shell script:
filecount=0;
for i in $(ls);
do
cd $i;
a=$(ls | wc -l) ;
filecount=$[filecount+a];
echo $filecount;
cd ..;
done

No comments: