recursiveprint() {
#FILES_COUNT=0
cd $1
for d in *; do
if [ -d "$d" ]; then
(recursiveprint "$d")
fi
if [ -f "$d" ]; then
file_name=$(basename "$d")
((FILES_COUNT++))
clear
echo "$file_name"
echo "total count = $FILES_COUNT"
fi
done
}
recursiveprint ${START_DIR}
The issue is, once it goes through one folder, it sets the count back to zero before iterating through another folder. Altogether, I have 30 files in different folders, the count ends up being 6 i.e the number of files in the last folder it iterates through. Any tips on how to solving this?