1

I have a directory named "BaseFile" with in this directory, I have few directories named "Dir1", "Dir2", "Dir3" etc.,

In these sub-directories, I have list of files which I need to get listed via code. Can Some one give me some tips on how to do this?

I need to do this both in windows and Linux platforms..

2vision2
  • 4,933
  • 16
  • 83
  • 164

2 Answers2

5

You can write this type of code using opendir() and readdir()

#include <dirent.h> 
#include <stdio.h> 

int main(void)
{
    DIR           *dirp;
    struct dirent *directory;

    dirp = opendir("/home/user/");
    if (dirp)
    {
        while ((directory = readdir(dirp)) != NULL)
        {
          printf("%s\n", directory->d_name);
        }

        closedir(dirp);
    }

    return(0);
}
Rahul R Dhobi
  • 5,668
  • 1
  • 29
  • 38
0

Boost provides a basic_directory_iterator which provides a C++ standard conforming input iterator which accesses the contents of a directory

Refer

http://www.boost.org/doc/libs/1_35_0/libs/filesystem/doc/reference.html

DNamto
  • 1,342
  • 1
  • 21
  • 42