Add r_file_find to recursive list files and subdirectories into a list ##util (#18526)

This commit is contained in:
RHL120 2021-04-02 01:04:06 +02:00 committed by GitHub
parent a0e5149df9
commit f85c995b51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

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

View File

@ -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;