Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stat system calls

Status
Not open for further replies.

CaptRage61

Programmer
Feb 17, 2005
50
US
Does anyone know how to use the Stat system calls to check if a file is a directory or just a file? I checked the man page and I found that you need to use S_ISDIR(m) but it does not say how to use it, does anyone know?
 
Yes. Use the macro against the st_mode member.
 
What would that look like?
I have :

DIR* d;
struct dirent *dirPointer;

dirPointer = readdir ( d );

How would I check to see if dirPointer is a directory or not using the stat commands??
 
Something like
Code:
struct stat sb;
struct dirent *dirPointer;

dirPointer = readdir ( d );      /* read a dir entry */
stat( dirPointer->d_name, &sb ); /* stat it */

if ( S_ISDIR( sb.st_mode ) ) {
  /* do something with the directory */
}

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top