【发布时间】:2011-05-01 23:49:10
【问题描述】:
好的,我有这样的事情:
struct dirent *dp;
DIR *dir;
char fullname[MAXPATHLEN];
char** tmp_paths = argv[1]; //Not the exact code but you get the idea.
...
while ((dp = readdir(dir)) != NULL)
{
struct stat stat_buffer;
sprintf(fullname, "%s/%s", *tmp_paths, dp->d_name);
if (stat(fullname, &stat_buffer) != 0)
perror(opts.programname);
/* Processing files */
if (S_ISDIR(stat_buffer.st_mode))
{
nSubdirs++;
DIRECTORYINFO* subd = malloc(BUFSIZ);
}
/* Processing subdirs */
if (S_ISREG(stat_buffer.st_mode))
{
nFiles++;
FILEINFO *f = malloc(BUFSIZ);
}
}
如何将文件名和子目录名读入我自己的结构 DIRECTORYINFO 和 FILEINFO?我浏览了 stat.h 并没有发现任何有用的东西。
【问题讨论】:
-
目录是 OS 功能,不是 C 的一部分。您必须指定平台。