Solved

readdir() ordering

Posted on 1998-12-15
3
375 Views
Last Modified: 2013-12-26
I am trying to use the unix directory manipulation routines opendir(), readdir(), etc. , but I need to know what order the directory will be returned in.  It seems on an HP that it is like a stack -- returning the last file written as the first file returned.  Is this always the case?

Marc
0
Comment
Question by:mpenner
3 Comments
 
LVL 2

Accepted Solution

by:
rdelfino earned 150 total points
ID: 1294868

it depends on the OS. in solaris I get the directory
listing in the ascending order using the following:

DIR *dirp;
struct dirent *dp;

printf(" directory listing of . :\n");
dirp =opendir(".");
if (dirp)
{
  dp = readdir(dirp);
 
  while(dp)
  {
    printf("%s\n", dp->d_name);
  }
  closedir(dp);
}

0
 
LVL 84

Expert Comment

by:ozo
ID: 1294869
If you want it in a particular order, you should sort it yourself
0
 

Author Comment

by:mpenner
ID: 1294870
Actually, I discovered that the true ordering is that you can't tell the ordering.  It seems to come from an internal representation of the directory, such that if you delete a file then add a new file it goes in the place of the deleted file in the ordering.  I tested this on HP and solaris.
Thanks for the code though.  It helped not to have to write it myself.


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

17 Experts available now in Live!

Get 1:1 Help Now