count file(s) under a specific directory

How do I count number of file in a directory. Here is what I want to do.

  1. find total number of file in a directory in variable total

  2. ftp all the file

  3. ftp_return_code=`grep -c "Transfer complete" $logfile`

if [$total == ftp_return_code]

  then
    exit 0

else

    exit -1

fi

man find

FAQ

sorry for the confusion, but I want to count how many file in the directory

man find

find . ! -name . -prune -type f

fileCount=`find . ! -name . -prune -type f   | wc -l`

or

fileCount=`ls -ltr | grep ^"-" | wc -l `

IF you want to have only regular files in the current directory without system files like .shell_profile, .sheel_history,.. .ssh then,

count=$(ls -l | awk '/^-/ { print $9 }')

If you want to have all files then,

count=$(ls -la | awk '/^-/ { print $9 }')

If you go for rcp / scp then it will be very easy to check return_code and transfer files one by one.

With ftp it will get more complex to check return code that, check and trasfer will be needed as one by one.

HTH.

# ls -a <dir> | wc -l

rather...

# ls -A <dir> | wc -l