![]() |
libdragon
|
Directory handling. More...
Go to the source code of this file.
Data Structures | |
struct | dir_t |
Directory entry structure. More... | |
Macros | |
Directory entry type definitions | |
#define | DT_REG 1 |
Regular file. | |
#define | DT_DIR 2 |
Directory. | |
Typedefs | |
typedef int(* | dir_walk_callback_t) (const char *fn, dir_t *dir, void *data) |
Callback function for directory walking. | |
Enumerations | |
enum | { DIR_WALK_ABORT = -2 , DIR_WALK_ERROR = -1 , DIR_WALK_CONTINUE = 0 , DIR_WALK_SKIPDIR = 1 , DIR_WALK_GOUP = 2 } |
Supported return values for dir_walk_callback_t. More... | |
Functions | |
int | dir_findfirst (const char *const path, dir_t *dir) |
Find the first file in a directory. | |
int | dir_findnext (const char *const path, dir_t *dir) |
Find the next file in a directory. | |
int | dir_walk (const char *path, dir_walk_callback_t cb, void *data) |
Walk a directory tree. | |
bool | dir_fnmatch (const char *pattern, const char *fullpath) |
Check if a filename matches a pattern. | |
int | dir_glob (const char *pattern, const char *path, dir_walk_callback_t cb, void *data) |
Glob a directory tree using a pattern. | |
Directory handling.
typedef int(* dir_walk_callback_t) (const char *fn, dir_t *dir, void *data) |
Callback function for directory walking.
This function is called for each file and each directory found during the directory walk.
The return value of this function determines the behavior of the directory walk. The possible return values are:
fn | The full absolute filename of the file or directory |
dir | The directory entry structure with information about the file or directory |
data | User data passed to dir_walk |
anonymous enum |
Supported return values for dir_walk_callback_t.
int dir_findfirst | ( | const char *const | path, |
dir_t * | dir | ||
) |
Find the first file in a directory.
This function should be called to start enumerating a directory or whenever a directory enumeration should be restarted.
[in] | path | Path to the directory structure |
[out] | dir | Directory entry structure to populate with first entry |
int dir_findnext | ( | const char *const | path, |
dir_t * | dir | ||
) |
Find the next file in a directory.
After finding the first file in a directory using dir_findfirst, call this to retrieve the rest of the directory entries. Call this repeatedly until a negative error is returned signifying that there are no more directory entries in the directory.
[in] | path | Path to the directory structure |
[out] | dir | Directory entry structure to populate with next entry |
int dir_walk | ( | const char * | path, |
dir_walk_callback_t | cb, | ||
void * | data | ||
) |
Walk a directory tree.
This function walks a directory tree, calling the callback for each file and directory found.
The callback is of type dir_walk_callback_t, and its return value determines the behavior of the walk. In fact, the callback can request to abort the walk (DIR_WALK_ABORT), skip the current directory (DIR_WALK_SKIPDIR), or stop walking the current directory and return up one level (DIR_WALK_GOUP). See dir_walk_callback_t for more information.
path | The path to the directory to walk |
cb | The callback function to call for each file and directory |
data | User data to pass to the callback |
bool dir_fnmatch | ( | const char * | pattern, |
const char * | fullpath | ||
) |
Check if a filename matches a pattern.
This function is a simplified version of fnmatch that only supports the following special characters:
?
- Matches any single character*
- Matches any sequence of characters, except '/'. It can be used to match multiple files in a single directory.**
- Matches any sequence of characters, including '/'. It can be used to match files within directory treesExample of patterns:
pattern | The pattern to match against |
fullpath | The full path to match |
int dir_glob | ( | const char * | pattern, |
const char * | path, | ||
dir_walk_callback_t | cb, | ||
void * | data | ||
) |
Glob a directory tree using a pattern.
This function walks a directory tree searching for files and directories that match a pattern. The pattern is a simplified version of fnmatch; see dir_fnmatch for more information about the supported special characters.
The callback function is called for each file and directory that matches the pattern. The callback can then decide how to proceed using its return value (see dir_walk_callback_t for more information).
pattern | The pattern to match against (see dir_fnmatch) |
path | The path to the directory to start the search |
cb | The callback function to call for each file and directory |
data | User data to pass to the callback |