filesystem

having a problem with checking to see if a directory exists:

#include <iostream>
#include <dirent.h>
#include <sys/stat.h>

using namespace std;

bool isdir(const char * filename) {
struct stat *buffer;
stat(filename, buffer);
if(S_ISDIR(buffer->st_mode) == 1) {
return true;
} else {
return false;
}
}

int listdir(const char * dirname) {

DIR *directory;
struct dirent *dirStruct;

directory = opendir(dirname);

while(dirStruct = readdir(directory)) {
if(isdir(dirStruct->d_name)) {
cout << dirStruct->d_name << "\n";
}
}

closedir(directory);
}

int main() {

listdir("C:/");

while(true);

}

I get a runtime error at if(isdir(dirStruct->d_name)) but it works fine if I put isdir("C:/"); or any other directory name it returns true, any files return false.?
[1040 byte] By [staticVoid] at [2007-11-20 11:42:25]
# 1 Re: filesystem
How to check for the existance of a directory/file? ( http://www.dev-archive.com/forum/showthread.php?t=330024)

Laitinen
laitinen at 2007-11-9 1:26:01 >
# 2 Re: filesystem
Sorry, I meant to say check if the file is a directory not if it exists.
staticVoid at 2007-11-9 1:27:04 >
# 3 Re: filesystem
you are not using windows are you? Unix?
laitinen at 2007-11-9 1:28:03 >
# 4 Re: filesystem
windows
staticVoid at 2007-11-9 1:29:08 >
# 5 Re: filesystem
Study the FAQ I gave you better! It is all there!
laitinen at 2007-11-9 1:30:04 >