Solved

readdir() ordering

Posted on 1998-12-15
3
370 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
Comment Utility

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
Comment Utility
If you want it in a particular order, you should sort it yourself
0
 

Author Comment

by:mpenner
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 105
substring method in java 1 79
matchUp  challenge 6 48
sumHeights  challenge 17 59
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

10 Experts available now in Live!

Get 1:1 Help Now