Q with stat()

From reading various articles on the net, I know stat() is used on files to get things like permissions, sizes etc... As a folder is a special type of file in Unix, I assumed that stat() could work on it as well as any general file.

However, from running my program, perror() reported that the folder does not exist, so Im curious to know what Ive done wrong


struct dirent *list;
DIR *d_entry;
struct stat buff;

/*Open directory & access 
elements within it*/

if( stat(list->d_name,&buff) == -1)
{
   perror("stat()");
}

else
{
....
}

thanks in advance

Hi diligent readers !!

Ive managed to solve my own problem. What I didn't do was specify the WHOLE path which was why it was complaining that it couldn't find the folder.

:slight_smile:

I have another question now.

Is stat() able to differ between executable files and folders accurately, or are the 2 considered the same ?

Im running into this issue atm, and have tried using


if(buff.st_mode == S_IFDIR)
{
...
}

without much success

Ok fixed prob

Used the S_ISDIR() macro to do the test instead and it worked ok.