Counting up files

Hi,

I have a load of if statements that look for files in a directory, I want to be able to count them up and the total files confirmed in an email? I ahve tried expr but i this does not work and it only reads in the first if and ignores the rest.

Please see script,

#!/bin/ksh

###########
#VARIABLES#
###########

RUNREF=`date +%Y%m%d`
DIR="../files/"
EMAIL="cdmspb"
MAIL_FROM="******"

email_user()
{
#Email
mail -t "$1" << EOF
Subject: $3
From: $2
$4
$5
$6
EOF
}

##########################################################################
#check files are in a directory and once it has checked, email out to user#
##########################################################################

TOTAL_FOUND="0"

    \#echo "Look for file $DIR/abc.txt"
    if [ -f $\{DIR\}abc.txt ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi
    
    \#echo "Look for file $DIR/def.out"
    if [ -f \{$DIR\}def.out ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi

    \#echo "Look for file $DIR/ghi.dat"
    if [ -f \{$DIR\}ghi.dat ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi
    
    \#echo "Look for file $DIR/jkl.csv"
    if [ -f \{$DIR\}jkl.csv ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi

    \#echo "Look for file $DIR/mno.txt"
    if [ -f \{$DIR\}mno.txt ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi
    
    \#echo "Look for file $DIR/pqr.dat"
    if [ -f \{$DIR\}pqr.dat ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi

       \#echo "Look for file $DIR/stu.txt"
    if [ -f \{$DIR\}stu.txt ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi
    
    \#echo "Look for file $DIR/vw.dat"
    if [ -f \{$DIR\}vw.dat ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi

    \#echo "Look for file $DIR/xy.dat"
    if [ -f \{$DIR\}xy.dat ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi
    
    \#echo "Look for file z.dat"
    if [ -f \{$DIR\}z.dat ]
    then
        TOTAL_FOUND=\`expr $TOTAL_FOUND \+ 1\`
    fi

FILE_LIST=`find $DIR`

# email all users
email_user "$EMAIL" "$MAIL_FROM" "Finished Running File Check : $RUNREF" "$TOTAL_FOUND File/s Found" "File/s available are" "$FILE_LIST"

##################################################

it is the TOTAL_FOUND that is not adding up at the end and when i get an email it only reads the first file lookup??

any help would greatly be appreciated!

If I'm not missing something you want to count all the files in your directory.
Why not simply:

TOTAL_FOUND=`find $DIR -type f|wc -l`
FILE_LIST=`find $DIR -type f`

Hi,

That works great, sorry new to unix and it looks like i was trying to make it harder than it actually needed to be.

Thanks again