Pages

To list files in directory in C

Friday 28 June 2013
This program lists all the files in a library / folder where the executable file is present. For example, if the executable file is present in C: \ \ TC \ \ BIN then displays all the files in C: \ \ TC \ \ BIN.

#include <stdio.h>
#include <conio.h>
#include <dir.h>

int main()
{
      int done;
      struct ffblk a;

      printf("Press any key to view the files in the current directory\n");
      getch();

      done = findfirst("*.*",&a,0);

      while(!done)
     {
         printf("%s\n",a.ff_name);
         done = findnext(&a);
     }
     getch();
     return 0;
}

No comments:

Post a Comment