Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Created August 25, 2024 07:58
Show Gist options
  • Save mortymacs/556827fc48ef6e7c3f6656799a0fb9d9 to your computer and use it in GitHub Desktop.
Save mortymacs/556827fc48ef6e7c3f6656799a0fb9d9 to your computer and use it in GitHub Desktop.
Read dir in C
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
int main()
{
struct dirent *entry;
DIR *dir;
dir = opendir("/home/user1/");
while((entry = readdir(dir)) != NULL)
{
printf("%s [%d]\n", entry->d_name, entry->d_type);
}
closedir(dir);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment