Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 22nd, 2006, 5:13 PM   #1
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
struct dirent: d_type invalid?

i keep getting an error saying that d_type is not a valid member of struct dirent, but isn't this meant to be the field that contains whether the object found is a file or a folder. i am using Dev-C++ 4 here is the code:
Quote:
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>

int main(int argc, char *argv[])
{
int numfiles=0;
DIR *dir;
struct dirent *read_dir;
dir=opendir("C:\\");
read_dir=readdir(dir);
if (dir != NULL)
{
while (read_dir = readdir (dir))
puts (read_dir->d_name);
(void) closedir (dir);
if(read_dir->d_type==DT_DIR)
{
}
}
else
puts ("Couldn't open the directory.");
getch();
return 0;
}
sorry just checked the header file(dirent.h) this d_type data field doesn't even exist can any body recommend any way to check if what is found is a file or a folder. I thank you in advanced for your replies.

Last edited by kruptof; May 22nd, 2006 at 5:38 PM.
kruptof is offline   Reply With Quote
Old May 22nd, 2006, 9:14 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
Use the stat function on the file name that is found and check
(StatBuffer.st_mode & S_IFDIR) != 0
The Dark is online now   Reply With Quote
Old May 23rd, 2006, 8:18 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Just a tip. "quote" tags don't preserve your indentation, "code" tags do. Thanks for trying, though.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC