>My question is this:
> I would like to go through the contents of a directory,
>filter out only the file extension I'm interested in, then sort
>them in file creation order.
> I've looked at the man pages for scandir & dirent, and I
>can't find anything that would let me sort on file creation time.
> Do I have to use scandir with a compare function that
>opens each directory entry & calls fstat every time?
> I'm hoping their is a quicker & simpler way.
>Thanks for your help
>Indranil
I would create a structure that contains a character string for the file name
and either an entire file stat structure or just the field that you are
interested in (ctime).
I would open the directory and read the entries, matching the entry name
against those that meet your extension criteria.
Valid files I would stat and then load their information into one of the
aforementioned structures. No need to actually open the file and incur the
additional overhead.
Place this structure into a binary tree that is sorted by your field/value of
interest.
When all pertinent files have been found do an inorder traversal of your
binary tree and your output is in the correct order.
- Steve Rountree
+-------------------------------------------------+
| Incomprehensible? But because you can not |
| understand a thing, it does not cease to exist. |
| |
| - Pascal (1670) |
+-------------------------------------------------+