Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Directory listing in C (http://www.go4expert.com/forums/directory-listing-c-t5030/)

hammil 1Jul2007 15:16

Directory listing in C
Hi all
does anyone know how to do a directory listing in C?
Also how I can include program parameters.

DaWei 1Jul2007 17:38

Re: Directory listing in C
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 1Jul2007 21:04

Re: Directory listing in C
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 !

shabbir 1Jul2007 23:45

Re: Directory listing in C
Offtopic comment:
Have the code block's when you have code snippets in the posts - http://www.go4expert.com/misc.php?do=bbcode#code

All times are GMT +5.5. The time now is 17:25.