Solved

Get date and Time stamp from dirent.h

Posted on 2002-06-20
3
1,597 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
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 50 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 178
chcp 65001 File encoding 66 267
Problem to scan all sheets 3 110
Loading flat file data in tables 2 39
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

792 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