mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-23 14:28:07 +00:00
Add r_file_find to recursive list files and subdirectories into a list ##util (#18526)
This commit is contained in:
parent
a0e5149df9
commit
f85c995b51
@ -54,7 +54,7 @@ R_API bool r_file_copy(const char *src, const char *dst);
|
||||
R_API bool r_file_move(const char *src, const char *dst);
|
||||
R_API RList* r_file_globsearch (const char *globbed_path, int maxdepth);
|
||||
R_API RMmap *r_file_mmap_arch (RMmap *map, const char *filename, int fd);
|
||||
|
||||
R_API bool r_file_dir_recursive(RList *dst, const char *dir);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1275,6 +1275,33 @@ R_API bool r_file_copy(const char *src, const char *dst) {
|
||||
#endif
|
||||
}
|
||||
|
||||
R_API bool r_file_dir_recursive(RList *dst, const char *dir) {
|
||||
bool ret = false;
|
||||
char *cwd = r_sys_getdir ();
|
||||
if (!cwd) {
|
||||
return false;
|
||||
}
|
||||
if (r_sys_chdir (dir) == false) {
|
||||
free (cwd);
|
||||
return ret;
|
||||
}
|
||||
RList *files = r_sys_dir (".");
|
||||
RListIter *iter;
|
||||
char *name;
|
||||
r_return_val_if_fail (files, false);
|
||||
r_list_foreach (files, iter, name) {
|
||||
if (strcmp (name, ".") == 0 || strcmp (name, "..") == 0) {
|
||||
continue;
|
||||
}
|
||||
r_list_append (dst, r_file_abspath (name));
|
||||
if (r_file_is_directory (name)) {
|
||||
ret = r_file_dir_recursive (dst, name);
|
||||
}
|
||||
}
|
||||
r_sys_chdir (cwd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void recursive_search_glob(const char *path, const char *glob, RList* list, int depth) {
|
||||
if (depth < 1) {
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user