读目录
#include <stdio.h> //perror()
#include <stdlib.h> //exit()
#include <dirent.h> //struct dirent,DIR,opendir(),readdir()
#include <string.h> //strcmp()
void die(char * s)
{
perror(s);
exit(1);
}
int main()
{
struct dirent * entry;
DIR * dir;
int id;
dir = opendir("/var/run/netns");
if (!dir)
{
die("opendir");
}
while ((entry = readdir(dir)))
{
if (strcmp(entry->d_name, ".") == 0)
continue;
if (strcmp(entry->d_name, "..") == 0)
continue;
printf("%s\n", entry->d_name);
}
closedir(dir);
return 0;
}
网友评论