#include
#include /* free() */
#include
int main(void) {
struct dirent **filelist = {0};
char *directory = ".";
int fcount = -1;
int i = 0;
fcount = scandir(directory, &filelist, 0, alphasort);
if(fcount < 0) {
perror(directory);
return 1;
}
for(i = 0; i < fcount; i++) {
printf("%02d: %s\n", i, filelist[i]->d_name);
free(filelist[i]);
}
free(filelist);
return 0;
}