testing directory S_ISDIR acts inconsistently
- by coubeatczech
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);
}