libostd/examples/listdir.cc

27 lines
582 B
C++
Raw Normal View History

2016-01-31 23:19:23 +01:00
#include <ostd/io.hh>
#include <ostd/filesystem.hh>
#include <ostd/range.hh>
2016-01-31 23:19:23 +01:00
using namespace ostd;
void list_dirs(ConstCharRange path, int off = 0) {
2016-05-25 18:12:28 +02:00
DirectoryStream ds{path};
2016-01-31 23:19:23 +01:00
/* iterate all items in directory */
for (auto v: iter(ds)) {
if (v.type() != FileType::directory) {
2016-01-31 23:19:23 +01:00
continue;
}
for_each(range(off), [](int) { write(' '); });
2016-01-31 23:19:23 +01:00
writeln(v.filename());
list_dirs(v.path(), off + 1);
}
}
int main(int argc, char **argv) {
if (argc < 1) {
return 1;
}
2016-01-31 23:19:23 +01:00
list_dirs(argv[1]);
return 0;
2016-02-07 22:17:15 +01:00
}