in reply to how to get total numbers of files in a directory?
Since you seem to work on a Un*x system you could also simply resort to command line tools that are quite up to this task. (That is, if you're only after the result of what you ask about.)
would do nicely, although it would count recursively, i.e. it would also count text files in subdirectories. If you want to limit the count to the specified directory, modify the above to read:
find /home/a -type f -name "*.txt" | wc -l
find /home/a -type f -name "*.txt" -maxdepth 0 | wc -l
The /home/a is the directory you want to search, -type f specifies that you're only interested in files, -name "*.txt" implies that you only want files that have a .txt suffix, -maxdepth 0 specifies that you want 0 levels of recursion, i.e. you want find to limit itself to the directory specified.
Learning how to use find definitely pays off, see the relevant man page for more info since it is really very powerful, especially when using the -exec flag.
Hope this helps, -gjb-