程式語言 - GNU - C/C++ - Open DIR



參考資訊:
https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c

main.c

#include <stdio.h>
#include <dirent.h>

int main(int argc, char **argv)
{
    DIR *dir = NULL;
    struct dirent *ent = NULL;

    dir = opendir("/tmp");
    while ((ent = readdir(dir)) != NULL) {
        printf("%s\n", ent->d_name);
    }
    closedir(dir);
    return 0;
}