Print Number of Files and Folders in given directory

 
#!/bin/bash
# Print Number of Files and Folders
if [ -d "$@" ]; then
echo "Files found: $(find "$@" -type f | wc -l)"
echo "Folders found: $(find "$@" -type d | wc -l)"
else
echo "[ERROR] Please try again."
exit 1
fi


[adimulamvenkat19851609@cxln4 ~]$ sh hello.sh
Files found: 134
Folders found: 33

[adimulamvenkat19851609@cxln4 ~]$ sh hello.sh dir2
Files found: 1
Folders found: 1

[adimulamvenkat19851609@cxln4 ~]$ sh hello.sh prabhu
Files found: 3
Folders found: 2

===========================================================
#!/bin/bash
LOCATION=$1
FILECOUNT=0
DIRCOUNT=0
for item in $LOCATION
do
if [ -f "$item" ]
    then
         FILECOUNT=$[$FILECOUNT+1]
    elif [ -d "$item" ]
        then
         DIRCOUNT=$[$DIRCOUNT+1]
fi
done
echo "File count: " $FILECOUNT
echo "Directory count: " $DIRCOUNT