?
Solved

readdir() ordering

Posted on 1998-12-15
3
Medium Priority
?
380 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 450 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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