Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Count all files and subfolder files within a folder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Count all files and subfolder files within a folder
Authored by: brettmjohnson on Nov 09, '04 02:13:23PM

It is, indeed trivial from the shell:

#!/bin/sh
# Specify the root of the tree as first parameter. Current directory is default.
echo "Total Apps: " `ls -aRF1 $1 | egrep '.*\.app/$' | wc -l`
echo "Total Files: " `ls -aRF1 $1 | egrep -v '^$|.*:$|.*/$' | wc -l`
echo "Total Folders: " `ls -aRF1 $1 | egrep -v '^\.{1,2}/$' | egrep '.*/$' | wc -l`

You could speed it up by writing the output of ls -aRF1 to a temp file and grepping through that temp file for the rest of the jobs.



[ Reply to This | # ]
Count all files and subfolder files within a folder
Authored by: kenahoo on Nov 10, '04 07:23:34PM

An easier and faster way is to use 'find':

#!/bin/sh
# Specify the root of the tree as first parameter.
echo "Total Apps: " `find $1 -name '*.app' | wc -l`
echo "Total Files: " `find $1 -not -type d | wc -l`
echo "Total Folders: " `find $1 -type d | wc -l`

-Ken



[ Reply to This | # ]