#include <stdio.h>
#include <dirent.h>
#include <string.h>
#define DIR_NAME "test_dir"
int main()
{
struct dirent *ep;
DIR *dp;
dp = opendir(DIR_NAME);
if(dp == NULL)
{
perror("can't open dir");
return -1;
}
while((ep = readdir(dp))!= NULL){
if(0 == strncmp(ep->d_name, "main", 4))
printf("%s\n", ep->d_name);
printf("%d\n", (int)ep->d_type);
}
}