C stat函数返回空结构

C stat函数返回空结构,c,file,directory,stat,C,File,Directory,Stat,我正在目录中搜索文件夹。问题是stat返回的dirdata中大多数文件夹的值都是空的,代码需要: studentsDir = opendir(lineValues); while ((entry = readdir(studentsDir)) != NULL) { stat(path, &dirData); if (S_ISDIR(dirData.st_mode) && (entry->d_name[0] != '.') &a

我正在目录中搜索文件夹。问题是stat返回的dirdata中大多数文件夹的值都是空的,代码需要:

studentsDir = opendir(lineValues);
while ((entry = readdir(studentsDir)) != NULL) {
    stat(path, &dirData);
    if (S_ISDIR(dirData.st_mode) && (entry->d_name[0] != '.')
            && (entry->d_name[1] != '.')) {
因此,您还需要:

  int stat(const char *path, struct stat *buf);
而*path变量需要是实际路径,可以是相对于目标文件的相对路径,也可以是绝对路径(带有文件名)

公布的代码中没有任何内容表明上述任何内容已包含在代码中

“entry”是指向“struct dirent”的指针,在stat使用它之前,当前文件/目录名需要附加到“path”中

在使用“entry”之前,需要检查它以确保它不为空

struct dirent包含将包含的d_name[256]字段 当前文件或目录的名称,但不是整个路径 所以每次代码进入子目录时, 发布的代码没有做什么 然后路径需要有来自d_name[]的字符串
附加到路径字符串后

检查stat的返回值,并可能检查errno。否则,程序是否具有检查文件的权限?
  int stat(const char *path, struct stat *buf);
struct stat dirData;