-3

I'm accessing a directory from my cross-platform c++ code. I know that this directory has three sub directories, but their names are randomly generated.

What I want is a list with the names of these directories (not files!) as type std::string. I would very much like to avoid using libraries, such as boost or qt, and keep to standard c++, if possible.

A.Faur
  • 93
  • 2
  • 8
  • There are no functionality in C++ (yet) to handle directories and directory walking. Either use a cross-platform library such as Boost, or code your own classes, that uses the native functionality of each platform. – Some programmer dude Aug 15 '13 at 11:47
  • filesystem stuff is platform specific, you can't perform such tasks without interfacing your program with something that is not portable, boost::filesystem let's you perform this task while abstracting the platform, it's a big plus. – user2485710 Aug 15 '13 at 11:48
  • As said, you need platform-specific code to access filesystem, so you need either `#ifdef`s for all the OSes supported by your app, or use some cross-platform library that have those `#ifdef`s inside. There are several libraries for this, Qt and boost are two of them as mentioned in comments, you can choose what you want – SpongeBobFan Aug 15 '13 at 12:07
  • There have been many questions as how to find files, like the one you mention Dariusz. Not folders. And no libraries allowed, that's unfortunately why I can't use boost! :-( – A.Faur Aug 15 '13 at 12:13

1 Answers1

0

I rolled my own... effectively implementing a "findFirst" and "findNext" approach. On Windows I used _findfirst and _findnext and the _finddata_t results can be utilized to determine if it's a directory or not (for recursion). On *nix platforms I used opendir and readdir then used stat to determine if it was a directory.

mark
  • 5,269
  • 2
  • 21
  • 34