Stat(filename, attrib) /looping problems

I am trying to write a loop that gets the modified dates from a directory of files. My problem is that it seems the call to stat(filename, attrib) is not replacing the information in the last call. It seems stuck on the second directory "." am i missing some deconstructor call or memory free? Note: the files in the directory were all created and modified at different times yesterday and today.

The code:
while ((dirp = readdir(dp)) != NULL)
stat(dirp->d_name, &attrib);
strftime(date, 20, "%y.%m.%d.%H.%M.%S", localtime(&attrib.st_mtime)));
printf("%s-%s\n", date,dirp->d_name);

the output:
If the files are not located in the current working directory stat will fail to read them because d_name only contains the file name, not the whole path.
Last edited on
Thanks. Such a simple error I dont think I would have ever realized it.
Topic archived. No new replies allowed.