Solved

readdir() ordering

Posted on 1998-12-15
3
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 140
dog bark java program 15 121
Use of condition with 'serial' in ansible 2 88
Bartender label printing - switch on and off graphics 3 77
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 …

730 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