我正在对目录中的所有文件进行简单测试。 但是由于某种原因,有时候,他们的行为是错误的? 我的代码有什么不好?测试目录S_ISDIR行为不一致
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);
}
请解释您的意思是“行为错误”。是否有目录输出为“other”,或其他输出为“dir”的东西? – 2010-05-15 20:32:18
@Roland Illig:都 – coubeatczech 2010-05-15 22:46:35