in reply to read closed directory handle?

You did a close() on a filehandle which is a directory. You need closedir().

Cheers,
KM