2017-05-03 00:14:27 +00:00
|
|
|
/** @example listdir.cc
|
|
|
|
*
|
2018-04-17 00:26:23 +00:00
|
|
|
* A simple example of using ostd::path and ostd::path::fs.
|
2017-05-03 00:14:27 +00:00
|
|
|
*/
|
|
|
|
|
2016-01-31 22:19:23 +00:00
|
|
|
#include <ostd/io.hh>
|
2018-04-16 01:20:23 +00:00
|
|
|
#include <ostd/path.hh>
|
2016-07-31 19:40:25 +00:00
|
|
|
#include <ostd/range.hh>
|
2016-01-31 22:19:23 +00:00
|
|
|
|
|
|
|
using namespace ostd;
|
|
|
|
|
2018-04-16 01:20:23 +00:00
|
|
|
inline void list_dirs(path const &path, int off = 0) {
|
|
|
|
fs::directory_range ds{path};
|
2017-03-10 17:19:59 +00:00
|
|
|
for (auto &v: ds) {
|
2018-04-17 21:13:46 +00:00
|
|
|
if (!v.is_directory()) {
|
2016-01-31 22:19:23 +00:00
|
|
|
continue;
|
2016-07-31 19:40:25 +00:00
|
|
|
}
|
|
|
|
for_each(range(off), [](int) { write(' '); });
|
2018-04-16 01:20:23 +00:00
|
|
|
writeln(v.path().name());
|
|
|
|
list_dirs(v.path(), off + 1);
|
2016-01-31 22:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2016-07-31 19:40:25 +00:00
|
|
|
if (argc < 1) {
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-31 22:19:23 +00:00
|
|
|
list_dirs(argv[1]);
|
|
|
|
return 0;
|
2016-02-07 21:17:15 +00:00
|
|
|
}
|