The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to man readdir(3) cy163 UNIX for Dummies Questions & Answers 1 07-07-2007 05:17 AM
Strange requirement!!! rahul26 UNIX for Advanced & Expert Users 1 08-19-2006 12:29 AM
Preblem with readdir system call gandhevinod Filesystems, Disks and Memory 2 02-16-2005 11:03 PM
system requirement for unix gparsons70 UNIX for Dummies Questions & Answers 3 10-24-2001 12:56 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-03-2008
Registered User
 

Join Date: Mar 2008
Posts: 11
Question diren.h : readdir( ) - sorting requirement

hi all,
im using dirent.h headers readdir() function to traverse down a directory ( after openning it with opendir() ), and im printing the dir->d_name in a program.
Code:
while(( dir = readdir( d ) ) != NULL ){
	
   if (stat([path+dir->d_name], &info) != 0){ 
      fprintf(stderr, "stat() error on %s: %s\n", path, strerror(errno));
      continue;
      }

if (S_ISDIR(info.st_mode) || S_ISREG(info.st_mode)) { 
   printf("%s\n", dir->d_name);
}
else{continue;}

}
note:[path+dir->d_name] is the path and current dir entrys name.

but the output this gives is not sorted according to any parameter(name, date.etc..).
is there a way to get such a sorted output using above dirent.h function calls or any other.
any help is greatly appreciated.
wolwy.
Reply With Quote
Forum Sponsor
  #2  
Old 06-03-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,059
Check out scandir(3) and alphasort().
Reply With Quote
  #3  
Old 06-08-2008
Registered User
 

Join Date: Mar 2008
Posts: 11
Thankx fpmurphy for the reply, actually i had it given up until i saw ur answer recently. it worked, up to my requirement, thankx.
wolwy.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0