http://www-128.ibm.com/developerworks/aix/library/au-unix-readdir.html
The dirent.h functions, opendir(), readdir(), and closedir(), are just what you need. Using them is very similar to the open/read/close idiom you're probably used to using with files, with one exception: the readdir() function returns a pointer to a special structure (of type struct dirent) for each directory entry
dir = opendir( "some/path/name" )
entry = readdir( dir )
while entry is not NULL:
do_something_with( entry )
entry = readdir( dir )
closedir( dir )
int readdir_r(DIR *, struct dirent *, struct dirent **);
struct dirent {
ino_t d_ino; /* file number of entry */
__uint16_t d_reclen; /* length of this record */
__uint8_t d_type; /* file type, see below */
__uint8_t d_namlen; /* length of string in d_name */
char d_name[__DARWIN_MAXNAMLEN + 1]; /* name must be no longer than this */
};
file type is list below,
DT_UNKNOWN
The file type is unknown.
DT_REG
This is a regular file.
DT_DIR
This is a directory.
DT_FIFO
This is a named pipe, or FIFO.
DT_SOCK
This is a Unix domain socket.
DT_CHR
This is a character device.
DT_BLK
This is a block device. |