Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

opendir/readdir - Don't they access directories in chrono. order ?

1 view
Skip to first unread message

John F Haugh II

unread,
Nov 14, 1991, 9:06:09 AM11/14/91
to
[ Not really an internals question, so I'm sending this off to
comp.unix.questions. ]

In article <75...@borg.cs.unc.edu> mirc...@schubert.cs.unc.edu (Jaideep Mirchandani) writes:
> I am trying to run a program which uses opendir/readdir
>to read the entries in a directory. I thought that this would
>access the entries in chronological order, so I set the timestamps of
>all the files in this directory in the order in which I wanted them read,
>by using 'touch'.
>
> Unfortunately, they were not read in time order, so I don't know how
>to control the program's output. Do you know how I can force opendir/readdir
>to read my file entries in a certain order.

readdir() returns the directory entries in some generally random
order, sort of related to time, but jumbled up as time goes by.
That is, if you start with an empty directory and add files to
it one by one, readdir() might give you the entries back in the
order you entered them. But generally speaking, it doesn't.

What you will probably have to do is set up a structure containing
the appropriate st_?time field and a pointer the file's name. Use
qsort() (or roll your own) and sort the resulting array of file
name/timestamp structures.
--
John F. Haugh II | I am the NRA. | UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 255-8251 | Shoot a friend today!| Domain: j...@rpp386.cactus.org
" ... expectation is the mother of disappointment."
-- Brad Konopik

KP KP

unread,
Aug 7, 2022, 7:58:14 PM8/7/22
to
In your loolie.
0 new messages