Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1896
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

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