libite
|
#include <errno.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
Functions | |
int | dir (const char *dir, const char *type, int(*filter)(const char *file), char ***list, int strip) |
List all files of a certain type in the given directory. More... | |
int dir | ( | const char * | dir, |
const char * | type, | ||
int(*)(const char *file) | filter, | ||
char *** | list, | ||
int | strip | ||
) |
List all files of a certain type in the given directory.
dir | Base directory for dir operation. |
type | File type suffix, e.g. ".cfg". |
filter | Optional file name filter. |
list | Pointer to an array of file names. |
strip | Flag, if set dir() strips the file type. |
This function returns a list of files, matching the type suffix, in the given directory dir.
The list argument is a pointer to where to store the dynamically allocated list of file names. This list should be free'd by first calling free() on each file name and then on the list itself.
If filter is not NULL
it will be called for each file found. If filter returns non-zero the file argument is included in the resulting list. If filter returns zero for given file it is discarded. If the strip flag is set the resulting list of files has their file type stripped, including the dot. So a match "config0.cfg" would be returned as "config0".