alibaba / PhotonLibOS

Probably the fastest coroutine lib in the world!

Home Page:https://PhotonLibOS.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I read a directory and get the list of files?

aley1 opened this issue · comments

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?

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);

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, ""))) {
    ...
}

Thank you all!