How do I read a directory and get the list of files?
aley1 opened this issue · comments
aley1 commented
Hi Photon team,
Sorry but I need some help even after looking through examples.
How do I use the photon filesystem to read a directory and get the list of filenames in the directory?
Bob Chen commented
libc has the readdir
method, and so does photon fs.
https://man7.org/linux/man-pages/man3/readdir.3.html
photon::fs::DIR* opendir(const char *name);
struct dirent* readdir(DIR *dirp);
Huiba Li commented
If you want to list sub-dir as well, you can use class Walker
in fs/path.h. See fs/test/test.cpp for an example.
for (auto file : enumerable(Walker(srcFs, ""))) {
...
}
aley1 commented
Thank you all!