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;
2017-02-16 18:48:14 +01:00
void list_dirs(string_range path, int off = 0) {
2017-02-16 20:39:05 +01:00
directory_stream ds{path};
2016-01-31 23:19:23 +01:00
/* iterate all items in directory */
for (auto v: iter(ds)) {
2017-02-16 20:39:05 +01:00
if (v.type() != file_type::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
}