The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
stat gajju UNIX for Advanced & Expert Users 6 09-08-2008 10:55 PM
How to stat X-Server on AIX 5.3 ??? touny AIX 5 11-20-2007 07:29 AM
Hi errno in sys/stat.h vijlak High Level Programming 6 11-11-2006 09:13 PM
Cannot Stat Error Homer Allman UNIX for Advanced & Expert Users 1 05-22-2006 11:07 AM
Cannot stat? lgardner UNIX for Dummies Questions & Answers 1 05-27-2005 05:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-11-2008
JamesGoh JamesGoh is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 89
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


Code:

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
  #2 (permalink)  
Old 09-11-2008
JamesGoh JamesGoh is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 89
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.

  #3 (permalink)  
Old 09-11-2008
JamesGoh JamesGoh is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 89
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


Code:

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

without much success
  #4 (permalink)  
Old 09-11-2008
JamesGoh JamesGoh is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 89
Ok fixed prob

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0