Solved

readdir() ordering

Posted on 1998-12-15
3
376 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prevent this page from creating additional dialogs. 3 532
Smart Camera scanning and reading information 3 106
matchUp  challenge 6 64
firstChar challenge 13 115
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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