libostd/examples/listdir.cc

31 lines
614 B
C++
Raw Normal View History

2017-05-03 02:14:27 +02:00
/** @example listdir.cc
*
2018-04-18 23:58:51 +02:00
* A simple example of using ostd::path and ostd::fs.
2017-05-03 02:14:27 +02:00
*/
2016-01-31 23:19:23 +01:00
#include <ostd/io.hh>
2018-04-16 03:20:23 +02:00
#include <ostd/path.hh>
#include <ostd/range.hh>
2016-01-31 23:19:23 +01:00
using namespace ostd;
2018-04-16 03:20:23 +02:00
inline void list_dirs(path const &path, int off = 0) {
fs::directory_range ds{path};
for (auto &v: ds) {
if (!v.is_directory()) {
2016-01-31 23:19:23 +01:00
continue;
}
for_each(range(off), [](int) { write(' '); });
2018-04-16 03:20:23 +02:00
writeln(v.path().name());
list_dirs(v.path(), off + 1);
2016-01-31 23:19:23 +01:00
}
}
int main(int argc, char **argv) {
2018-04-20 01:23:47 +02:00
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
}