0

I'm finding a way to fetch all the subfolders in a known folder, and open them, then keep finding all the subfolders in that folder, keep opening them until there aren't any subfolders left more, then move to another folder in C++. Thanks for help!

  • 4
    IMHO, this is too broad for a SO question. If your environment support C++17 or above, you can use the [`std::filesystem`](https://en.cppreference.com/w/cpp/filesystem) library. Else you can find it in boost. If neither is an option, you will have to use OS specific calls. – Serge Ballesta Sep 24 '21 at 11:08
  • Thanks for helpful tips are are welcome, but don't forget to accept and/or upvote the answer. It took someone's time and effort to write it for you, just for free. – zkoza Oct 01 '21 at 21:59

1 Answers1

1

Following up on Serge Ballesta's comment.

If you can compile c++17, then make use of std::filesystem.

However, if you are not able to run c++17, then you need to consider the OS you are working on.

If Linux and using GCC, use native "dirent.h"

  • SO post with solution.
  • Just need to #include dirent.h

If Windows, can use either windows.h or use a popular libarary extension of dirent.h for windows.

  • If using windows.h native methods, here is a SO post with solution.

  • If using windows extended dirent.h. Here is the github link. Just need to grab the header and add to your project.

    • Can be nicer if working cross platform
    • I just used this on my project, and was very convenient and easy.
Frebreeze
  • 202
  • 3
  • 10