![]() |
libdragon
|
Directory traversal, pattern matching, and globbing utilities. More...
Enumerations | |
enum | fnmatch_result_t { NO_MATCH = 0 , PARTIAL_MATCH = 1 , FULL_MATCH = 2 } |
Functions | |
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 traversal, pattern matching, and globbing utilities.
enum fnmatch_result_t |
Return values for fnmatch_partial
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 |