?
Solved

Get date and Time stamp from dirent.h

Posted on 2002-06-20
3
Medium Priority
?
1,704 Views
Last Modified: 2012-08-14
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
Comment
Question by:Loysi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Expert Comment

by:newmang
ID: 7097500
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
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 7098609
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
 

Author Comment

by:Loysi
ID: 7098630
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question