2

I am not sure if this is possible but is it possible to loop through files in a directory in c++?

For example, how do I know how many files there are in a directory from c++ file and how do I individually call that file instead of manually giving the path to each file which would be extremely painful?

while(1){
   pcl::io::loadPCDFile<pcl::PointXYZ> ("getFiles.pcd", *cloud1); <-- each file
}
Bart
  • 19,692
  • 7
  • 68
  • 77
ealeon
  • 12,074
  • 24
  • 92
  • 173
  • Possible duplicate of [How can I get the list of files in a directory using C or C++?](https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c) – jaminka evening Jun 01 '17 at 21:30

1 Answers1

3

There are OS-specific solutions, like

  • opendir and readdir on Linux
  • FindFirstFile and FindNextFile on Windows

or you can use Boost Filesystem, which has already figured out all the OS-specific bits.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720