Thread: Improvements on Recursive Directory Listing

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    4

    Improvements on Recursive Directory Listing

    Hi i am a relative newb to C programming, in a unix environment i am attempting to create a C program that does a recursive directory listing, functionaly similar to "ls -lR"

    So far i have come up with this

    Code:
    #include <sys/types.h>
    #include <dirent.h>
    #include <stdio.h>
    
    int main( int argc, char* argv[] )
    {
      DIR * dir;
      struct dirent * entry;
      dir = opendir( argv[1] );
      while ( entry=readdir( dir ) ) {
        printf( "%s\n", entry->d_name );
      }
      closedir( dir );
      return 0;
    }

    Does any1 have any ideas how i could improve this with the use of chdir, stat and any other procedures which could improve its performance???

    any help would be greatly recieved

    many thanks

    laney

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://faq.cprogramming.com/cgi-bin/...&id=1044780608
    Particularly the program listed below "The following is an expanded example for Unix systems."
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  2. PLEASE HELP ME!!! Recursive directory listing
    By laney69er in forum C Programming
    Replies: 1
    Last Post: 03-15-2006, 07:08 AM
  3. recursive directory listing help
    By laney69er in forum C Programming
    Replies: 2
    Last Post: 03-13-2006, 01:07 PM
  4. Trying to write a recursive directory listing
    By crazeinc in forum C Programming
    Replies: 4
    Last Post: 04-28-2005, 12:35 AM
  5. Directory listing
    By brif in forum C++ Programming
    Replies: 1
    Last Post: 10-10-2002, 06:44 AM