- Dirent.h
dirent.h is the header in the
C POSIX library for theC programming language that contains constructs that facilitate directory traversing. The function is not part of the C standard, but is considered "pseudo-standard" and is reliably portable between platforms.Member functions
Member constants
Constants defined in the
stdio.h
header include:Member types
Data types defined in the
dirent.h
header include:
*DIR
- A structure representing a directory stream. Contains the following members::*struct _finddata_t dd_dta
- disk transfer area:*struct dirent dd_dir
- dirent structure:*long dd_handle
:*int dd_stat
- status of search: 0 = not started yet, -1 = off the end, positive = 0-based index of next entry*
struct dirent
- A structure with the following members::*off_t d_off
- not in all implementations:*unsigned short d_namlen
- Length of name in d_name:*unsigned short d_reclen
:*ino_t d_ino
- file serial number:*char d_name []
- name of entry (will not exceed a size of NAME_MAX)[http://www.gimp.org/~tml/gimp/win32/dirent.zip Free Windows implementation of dirent.h]
A short example of dirent.h usage is:char **files=NULL;void GetAllFiles(char *path, char*** files){ DIR *dir = opendir(path); struct dirent *dp; int i=0, j=0; char *tmp; while ((dp=readdir(dir)) != NULL) { i++; //counting number of files in directory (files+dirs) } rewinddir(dir); (*files) = (char **)malloc(i*sizeof(char*)); while ((dp=readdir(dir)) != NULL) { (**files) = strdup(dp->d_name); printf("%s ",dp->d_name); (*files)++; i++; } closedir(dir);}
Wikimedia Foundation. 2010.