Apparently readdir, opendir, closedir are UNIX functions and not available on windows.
UPDATE: I found some C code ported to windows which works. See link here:
http://www.two-sdg.demon.co.uk/curbralan/code/dirent/dirent.html
http://www.two-sdg.demon.co.uk/curbralan/code/dirent/dirent.c
http://www.two-sdg.demon.co.uk/curbralan/code/dirent/dirent.h