How to check for filetype existence quickly

I have directory, say "c:\documents" on Windows or "/home/petr/ documents" on Linux. In this directory many files are stored with many filetypes (extensions), say *.doc, *.txt, *.zip. I need to find fastes way how to check if some filetype exist. Now I use routine where I use readdir() and return true if passed filetype is first time found but