Open directory using C

You should really post your code(a), but here goes. Start with something like: #include <stdio.h> #include <dirent.h> int main (int argc, char *argv[]) { struct dirent *pDirent; DIR *pDir; // Ensure correct argument count. if (argc != 2) { printf (“Usage: testprog <dirname>\n”); return 1; } // Ensure we can open directory. pDir = opendir … Read more

Checking if a dir. entry returned by readdir is a directory, link or file. dent->d_type isn’t showing the type

d_type is a speed optimization to save on lstat(2) calls, when it’s supported. As the readdir(3) man page points out, not all filesystems return real info in the d_type field (typically because it would take an extra disk seek to read the inode, as is the case for XFS if you didn’t use mkfs.xfs -n … Read more