in reply to "readdir() attempted on invalid dirhandle" error?

opendir, not open. You are doing the opposite, trying to read a directory as a file.