GP2X Readdir


craigix

Mega GP Mania
Joined
Feb 3, 2003
Messages
11,008
Location
England
Website
twitter.com
Does anyone know how to tell when readdir returns a dir name and not a file name? It just seems to give you a list of the current dir contents regardless of type.

Google does not seem to know the answer either, I have came up with a complex way of finding out if each entry is a file or dir but it seems a bit over the top and time consuming, how do other people do it?

Thanks,

Craig

I posted too soon, someone posted the answer to my question on the dev channel just now:

<Mindlord> craigx... stat(entry->d_name, &statbuf)... if S_ISDIR(statbuf.st_mode) it's a DIR, if S_ISREG(statbuf.st_mode) it's a regular file... see: http://www.scit.wlv.ac.uk/~jphb/spos/notes/calls/stat.html
<craigix> thanks :)
<Mindlord> No prob
 
I remember looking into this before for something... Apparently on Linux there are extra fields in the dirent struct, so you can scan a directory more quickly because you don't have to stat each file. Check the d_type field. This may not work on cygwin, other OS's.
 
Back
Top