0

I want to list all the txt files in my "Derived Data" Folder, but so far the only thing that I can find that works for macOS is glob.h which I have placed like this, that just outputs the pathname I put in.

glob_t glob_result;
    glob("/Users/me/Desktop/XJ/DerivedData", GLOB_TILDE,NULL,&glob_result);
    for(unsigned int i=0; i<glob_result.gl_pathc; ++i){
        cout << glob_result.gl_pathv[i] << endl;

The boost/filesystem thing doesn't seem to work. Although it might be because of mac pathname styles. Is there any easier way to view all the files inside this folder on macOS?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Universe31
  • 45
  • 3
  • https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c. – Black Arrow Jun 10 '19 at 03:53
  • @BlackArrow like I said, it doesn't apply to MacOS supposedly. – Universe31 Jun 10 '19 at 04:11
  • An excerpt from Peter parker's answer in the aforementioned link:In C++17 there is now an official way to list files of your file system: std::filesystem. There is an excellent answer from Shreevardhan below with this source code: #include #include #include namespace fs = std::filesystem; int main() { std::string path = "/path/to/directory"; for (const auto & entry : fs::directory_iterator(path)) std::cout << entry.path() << std::endl; } – Hemil Jun 10 '19 at 04:11
  • @Hemil I saw that, but everytime I put in the path (see above), it doesn't work :/ – Universe31 Jun 10 '19 at 04:25
  • I am sorry but I don't have access to a mac. What happens exactly? It doesn't work means? The program does nothing or what? @Universe31 – Hemil Jun 10 '19 at 04:29
  • And can you use C++ 17? – Hemil Jun 10 '19 at 04:29
  • @Hemil everything that I've found so far is that the c++ 17 library isn't available on Xcode and that it uses c++ 11. It gives me the error that it can't find the library. – Universe31 Jun 10 '19 at 04:35
  • According to [51288230](https://stackoverflow.com/questions/51288230/how-to-enable-c17-in-xcode-for-mac-osx) Xcode should support c++17 given the corresponding settings. Give us more information about your enviroment (OS and xcode version, etc.) and the error, what exactly it says. – Black Arrow Jun 10 '19 at 05:27

0 Answers0