Skip to content

Instantly share code, notes, and snippets.

@evaporei
Last active April 24, 2025 21:16
Show Gist options
  • Save evaporei/73dc4fa0f2823ce96783f3858a9f135d to your computer and use it in GitHub Desktop.
Save evaporei/73dc4fa0f2823ce96783f3858a9f135d to your computer and use it in GitHub Desktop.
scandir example
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
int main(void) {
struct dirent **namelist;
int n = scandir(".", &namelist, NULL, alphasort);
if (n < 0) {
perror("scandir");
} else {
for (int i = 0; i < n; i++) {
printf("%s\n", namelist[i]->d_name);
free(namelist[i]);
}
free(namelist);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment