1

I have about 6000 .txt files to read. There are many folders, each containing many sub-folders, which again contain many sub-folders and at the end of every sub-folder there is a text file. the text file contains few numbers which I have to read. My issue is recursively going through the folders and sub-folders.

I am able to do this in Python, but not in C++.

Can someone help me with C++ (preferably without Boost)

labmat
  • 193
  • 1
  • 1
  • 10
  • Hints: 1) Keep the path as a `std::string`. 2) Use `std::stack` to help traverse the file system. – Thomas Matthews Oct 26 '16 at 16:00
  • BTW, if you are not using Boost, you will need platform specific API to access the filesystem. – Thomas Matthews Oct 26 '16 at 16:01
  • Boost, platform API, or C libraries are the ways to do this. – crashmstr Oct 26 '16 at 16:06
  • Possible duplicate of [How do you iterate through every file/directory recursively in standard C++?](http://stackoverflow.com/questions/67273/how-do-you-iterate-through-every-file-directory-recursively-in-standard-c) – crashmstr Oct 26 '16 at 16:06

2 Answers2

4

Unfortunately, best available thing is boost::filesystem::recursive_directory_iterator or, in case of fresh compiler - std::experimental::filesystem::recursive_directory_iterator

Examples are available in links provided

Starl1ght
  • 4,422
  • 1
  • 21
  • 49
0

I assume, from your mention of Boost, that you are aware of boost::filesystem, but are looking for an alternative. I'm not aware of any that are portable. A portable file system library is planned for the C++17 Standard Library, but it is based on boost::filesystem. On POSIX-compliant OSes, you could perhaps use the API functions declared in the dirent.h POSIX (straight C) header.

WaltK
  • 724
  • 4
  • 13