testing directory S_ISDIR acts inconsistently
Posted
by coubeatczech
on Stack Overflow
See other posts from Stack Overflow
or by coubeatczech
Published on 2010-05-15T19:56:00Z
Indexed on
2010/05/15
20:14 UTC
Read the original article
Hit count: 213
hi, I'm doing simple tests on all files in directory. But from some reason, sometimes, they behave wrongly? What's bad with my code?
using namespace std;
int main() {
string s = "/home/";
struct dirent * file;
DIR * dir = opendir(s.c_str());
while ((file = readdir(dir)) != NULL){
struct stat * file_info = new (struct stat);
stat(file->d_name,file_info);
if ((file_info->st_mode & S_IFMT) == S_IFDIR)
cout << "dir" << endl;
else
cout << "other" << endl;
}
closedir(dir);
}
© Stack Overflow or respective owner