• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1837
  • Last Modified:

Get date and Time stamp from dirent.h

On a Unix/Aix System the dirent.h structure does not save information of the files date and time stamp.
I would like to code a program on an AIX box where I read and process files based on a first come basis. However Unix opendir() sorts the file in alphabetic order by default. struct _dirdesc does not have members which hold the date and time stamp.
Can anyone direct to a function/procedure that will give me the date and time stamp info of the file read by readdir(DIR *) ?
0
Loysi
Asked:
Loysi
1 Solution
 
newmangCommented:
I take it you want to use the opendir and readdir functions to get the names of all the files in a particular directory and then process each of those files in date order....

If so I think the best way around this is to use the opendir and readdir functions to get the file names and then use the stat or lstat function to determine the date you are interested in (mtime, ctime or atime) for each file. You could build a linked list or similar in date order containing the dates and file names which could then be used to drive subsequent processing of the files.

Does this help?

Cheers - Gavin
0
 
jkrCommented:
Why don't you just call 'stat()' to get the time stamp? E.g.

struct dirent de;

//...

struct stat st;
time_t modified_last;

stat ( de.d_name, &st);

modified_last = st.st_mtime;
0
 
LoysiAuthor Commented:
Thanks! a much better approach that what I was thinking off.
I got to wound up with the dirent.h in unix and couldn't figure a way to make it work like the direct.h in Dos.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now