diff --git a/library/modules/Filesystem.cpp b/library/modules/Filesystem.cpp index a182ac062..2c275ceba 100644 --- a/library/modules/Filesystem.cpp +++ b/library/modules/Filesystem.cpp @@ -255,13 +255,14 @@ static int listdir_recursive_impl (std::string prefix, std::string path, std::string path_file = path + *file; if (Filesystem::isdir(prefixed_file)) { + files.insert(std::pair(include_prefix ? prefixed_file : path_file, true)); + if (depth == 0) { out_of_depth = true; continue; } - files.insert(std::pair(include_prefix ? prefixed_file : path_file, true)); err = listdir_recursive_impl(prefix, path_file + "/", files, depth - 1, include_prefix); if (err) return err; @@ -277,5 +278,7 @@ static int listdir_recursive_impl (std::string prefix, std::string path, int Filesystem::listdir_recursive (std::string dir, std::map &files, int depth /* = 10 */, bool include_prefix /* = true */) { + if (dir.size() && dir[dir.size()-1] == '/') + dir.resize(dir.size()-1); return listdir_recursive_impl(dir, "", files, depth, include_prefix); }