【发布时间】:2015-04-14 13:09:17
【问题描述】:
我正在使用dirent.h 递归地读取目录中的文件。在我的Debian GNU/Linux 7 (wheezy) 机器上它可以正常工作,但是在Ubuntu 12.04 LTS 服务器上它会将所有文件读取为 DT_UNKOWN!
if ((dir = opendir (input_dir)) != NULL)
{
while ((ent = readdir (dir)) != NULL)
{
// cat dir path to file
char full_file_path[FILE_NAME_LENGTH];
strcpy (full_file_path, input_dir);
strcat (full_file_path, "/");
strcat (full_file_path, ent->d_name);
// if "." or "..", skip it
if (!strcmp (ent->d_name, ".") || !strcmp (ent->d_name, ".."));
// if a regular file, process it
else if (ent->d_type == DT_REG)
{
process_file (full_file_path, f_out, z, ws);
}
// if a directory, recurse through it
else if (ent->d_type == DT_DIR)
{
// add '/' to the end of the directory path
process_directory (full_file_path, f_out, z, ws);
}
else
{
printf ("%s is neither a regular file nor a directory!\n",
full_file_path);
}
}
}
【问题讨论】:
-
我对 DT_UNKOWN 有两个想法:1)dirent 不支持服务器的文件系统(查看文档); 2)您的应用程序在访问权限方面存在一些问题(尝试使用 sudo 运行)
-
原来是(1)是我的情况,文件系统是dirent不支持的jfs。谢谢!
标签: c ubuntu-12.04 dirent.h