OK. First things first. These functions are NOT part of the ANSI standard library. They may not be supported on your platform.
Here is a quick summary of each Funktion, they are listed in the order in which you may want to execute them. opendir Open a directory stream. readdir read the current entry in the stream. scandir Find an entry in a direcory. seekdir Jump to a directory offset. telldir Return the current location within the directory stream. rewinddir Return to the start of the directory stream. closedir Close a directory.
Library: dirent.h
Prototype: DIR *opendir(const char *name);
struct dirent *readdir(DIR *dir);
int scandir(const char *dir, struct dirent ***namelist,
int (*select)(const struct dirent *),
int (*compar)(const void *, const void *));
void seekdir(DIR *dir, off_t offset);
off_t telldir(DIR *dir);
void rewinddir(DIR *dir);
int closedir(DIR *dir);
The dirent structure does not seem to be documented in the man pages, so here it is.
struct dirent
{
long d_ino;
off_t d_off;
unsigned short d_reclen;
char d_name[NAME_MAX+1];
};
example
program using opendir, readdir and closedir.
stat
Funktion.
opendir
readdir
scandir
seekdir
telldir
rewinddir
closedir