libostd/examples/listdir.cc

23 lines
525 B
C++
Raw Normal View History

2016-01-31 23:19:23 +01:00
#include <ostd/io.hh>
#include <ostd/filesystem.hh>
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: ds.iter()) {
if (v.type() != FileType::directory)
continue;
2016-02-04 20:08:02 +01:00
for (int i = 0; i < off; ++i) 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;
list_dirs(argv[1]);
return 0;
2016-02-07 22:17:15 +01:00
}