scandir
)#include <stdio.h> #include <dirent.h> static int isNotDotFile(const struct dirent *entry) { return entry->d_name[0] != '.'; } int main(void) { struct dirent **namelist; int i, n; n = scandir(".", &namelist, isNotDotFile, alphasort); if (n < 0) perror("scandir"); else { for (i = 0; i < n; ++i) { printf("%s\n", namelist[i]->d_name); free(namelist[i]); } free(namelist); } return 0; }
POSIX互換でない上に,度々仕様が変わるようで,たいへん不安….