0

I'm trying to add all the files in the current directory to my implemented archive. What function(s) could I use to access all these files? After doing some research online and in the man pages, all I have found is simple I/O like read, write, close, etc.

CS Gamer
  • 225
  • 1
  • 3
  • 12

3 Answers3

0

In Unix, readdir ; in Windows, see here for FindFirstFile(). Then go file by file in a loop and do what you want.

Community
  • 1
  • 1
PKG
  • 579
  • 6
  • 17
0

This web page seems to have what you want.

http://www.gnu.org/software/libc/manual/html_mono/libc.html#Opening-a-Directory

Marichyasana
  • 2,966
  • 1
  • 19
  • 20
0

You can try with this.

main() {
   DIR *d;
   struct dirent *e;

   e=malloc(sizeof(struct dirent));
   d=opendir("<your_directory_name>");

   while ((e = readdir(d)) != NULL) {
      printf("%d %s\n", e->d_type, e->d_name);
   }

   closedir(d);
}
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
Manik Sidana
  • 2,005
  • 2
  • 18
  • 29