update listdir example to use path
parent
0d0655b09e
commit
755e0f3934
2
build.cc
2
build.cc
|
@ -28,7 +28,7 @@ namespace fs = ostd::filesystem;
|
|||
/* ugly, but do not explicitly compile */
|
||||
#include "src/io.cc"
|
||||
#include "src/process.cc"
|
||||
#include "srC/path.cc"
|
||||
#include "src/path.cc"
|
||||
#include "src/filesystem.cc"
|
||||
#include "src/thread_pool.cc"
|
||||
#include "src/channel.cc"
|
||||
|
|
|
@ -4,21 +4,20 @@
|
|||
*/
|
||||
|
||||
#include <ostd/io.hh>
|
||||
#include <ostd/filesystem.hh>
|
||||
#include <ostd/path.hh>
|
||||
#include <ostd/range.hh>
|
||||
|
||||
using namespace ostd;
|
||||
|
||||
inline void list_dirs(filesystem::path const &path, int off = 0) {
|
||||
filesystem::directory_iterator ds{path};
|
||||
inline void list_dirs(path const &path, int off = 0) {
|
||||
fs::directory_range ds{path};
|
||||
for (auto &v: ds) {
|
||||
auto p = filesystem::path{v};
|
||||
if (!filesystem::is_directory(p)) {
|
||||
if (!fs::is_directory(v.path())) {
|
||||
continue;
|
||||
}
|
||||
for_each(range(off), [](int) { write(' '); });
|
||||
writeln(p.filename());
|
||||
list_dirs(p, off + 1);
|
||||
writeln(v.path().name());
|
||||
list_dirs(v.path(), off + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -150,6 +150,7 @@ OSTD_EXPORT void rdir_range_impl::read_next() {
|
|||
if (p_handles.empty()) {
|
||||
return;
|
||||
}
|
||||
/* can't reuse info from dirent because we need to expand symlinks */
|
||||
if (is_directory(p_current.path())) {
|
||||
/* directory, recurse into it and if it contains stuff, return */
|
||||
DIR *nd = opendir(p_current.path().string().data());
|
||||
|
|
Loading…
Reference in New Issue