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.
Thanks!
0
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.
0
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 !

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 shabbir; 1Jul2007 at 23:44.. Reason: Code block - http://www.go4expert.com/forums/misc.php?do=bbcode#code
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Offtopic comment:
Have the code block's when you have code snippets in the posts - http://www.go4expert.com/misc.php?do=bbcode#code