Directory listing in C

hammil's Avatar, Join Date: Jun 2007
Newbie Member
Hi all
does anyone know how to do a directory listing in C?
Also how I can include program parameters.
DaWei's Avatar, Join Date: Dec 2006
Team Leader
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.
kush_2207's Avatar, Join Date: Jun 2007
Go4Expert Member
Yes it is possible to do directory listing using C.
I hope this will suffice. No need for explaination !

#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 shabbir; 1Jul2007 at 23:44.. Reason: Code block -
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Offtopic comment:
Have the code block's when you have code snippets in the posts -