Ok I have something like this:
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);
}
}
How do I go about reading in the file names and subdirectory names into my own structure DIRECTORYINFO and FILEINFO? I've gone through stat.h and haven't found anything useful.