Solved

Get date and Time stamp from dirent.h

Posted on 2002-06-20
3
1,504 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
3 Comments
 
LVL 4

Expert Comment

by:newmang
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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 and use conditional statements in the C programming language.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now