Directory listing in C

Discussion in 'C' started by hammil, Jul 1, 2007.

  1. hammil

    hammil New Member

    Joined:
    Jun 28, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi all
    does anyone know how to do a directory listing in C?
    Also how I can include program parameters.
    Thanks!
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    For your first question, it depends entirely upon your system. For your second, you need to explain what you mean. Have a look here, both posts.
     
  3. kush_2207

    kush_2207 New Member

    Joined:
    Jun 26, 2007
    Messages:
    49
    Likes Received:
    1
    Trophy Points:
    0
    Yes it is possible to do directory listing using C.
    I hope this will suffice. No need for explaination !

    Code:
    #include <stdio.h>
    #include <dir.h>
    
    int main(void)
    {
       struct ffblk ffblk;
       int done;
       printf("Directory listing of *.*\n");
       done = findfirst("*.*",&ffblk,0);
       while (!done)
       {
          printf("  %s\n", ffblk.ff_name);
          done = findnext(&ffblk);
       }
    
       return 0;
    }
    
    
    struct ffblk is a structure storing all the relevant parameters required to list a directory. Use help in C for more details.
    findnext function call returns the next file in the directory

    Comments as always welcomed !
     
    Last edited by a moderator: Jul 1, 2007
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,341
    Likes Received:
    379
    Trophy Points:
    83

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice