c++ how to create a directory from a path

SHCreateDirectoryEx() can do that. It's available on XP SP2 and newer versions of Windows.


If you can use an external library, I'd look at boost::filesystem

#include <boost/filesystem.hpp>
namespace fs=boost::filesystem;

int main(int argc, char** argv)
{
    fs::create_directories("/some/path");
}

I'd write a loop. Split the path into components, and "walk it", i.e. starting at the beginning, check to see if it exists. If it does, enter it and continue. If it does not, create it, enter it and continue. For bonus points, detect if a component exists, but is a file rather than an a directory.

Tags:

C++

Directory