libite
Functions
dir.c File Reference
#include <errno.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for dir.c:

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...
 

Detailed Description

Author
Joachim Wiberg
Date
2008-2021

Function Documentation

◆ dir()

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.

Parameters
dirBase directory for dir operation.
typeFile type suffix, e.g. ".cfg".
filterOptional file name filter.
listPointer to an array of file names.
stripFlag, 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".

Returns
The number of files in list, zero if no matching files of type, or non-zero on error with errno set.