When you read a directory with readdir(3), the file type is stored in the d_typemember variable of each struct direntone you get, not in d_ino. You will rarely care about the inode number.
However, not all implementations will have reliable data for a member d_type, so you may need to call stat(3)either lstat(3)in each file to determine its file type (use lstatif you are interested in symbolic links, or use statif you are interested in the purpose of symbolic links) and then look at the element st_mode, using macros S_IS***.
A typical directory iteration might look like this:
DIR *dir = opendir(dir_to_read);
struct dirent *entry;
while((entry = readdir(dir)) != NULL)
{
struct stat st;
char filename[512];
snprintf(filename, sizeof(filename), "%s/%s", dir_to_read, entry->d_name);
lstat(filename, &st);
if(S_ISDIR(st.st_mode))
{
}
else if(S_ISLINK(st.st_mode))
{
}
else if(S_ISREG(st.st_mode))
{
}
}
closedir(dir);
source
share