In my code, I'm using readdir to get the listing from a directory. Not sure the difference, maybe you can tell me - I haven't looked at this in a while.
When you have the filename, you can run the stat command on it. After that, you can use the S_ISDIR macro as in:
#include <sys/stat.h>
...
struct stat status_buff;
...
stat_return = stat(incom_file, &status_buff);
if (stat_return == ERR_RETURN)
{
ERROR STUFF
}
if (S_ISDIR(status_buff.st_mode))
{
DIRECTORY CODE
}
else
{
FILE CODE
}
I hope that helps and does what you want. Let me know if something isn't quite right, but this works for me and has been in production for years. WARNING: The stat command can error off if the system resources are very heavily loaded - it happens occasionally on the HP boxes we run on.
Good luck!