I\'m trying to create a function that takes the name of a directory (C:\\foo\\bar, or ..\\foo\\bar\\..\\baz, or \\\\someserver\\foo\\bar
For Windows XP and up. Expects widechar null terminated string and amount of recursive actions as parameters. Was not tested with more than 1 level yet.
Note: Path seperators must be '\'
bool CreateRecursiveDirectoryW(const wchar_t* filepath, const int max_level)
{
bool result = false;
wchar_t path_copy[MAX_PATH] = {0};
wcscat_s(path_copy, MAX_PATH, filepath);
std::vector path_collection;
for(int level=0; PathRemoveFileSpecW(path_copy) && level < max_level; level++)
{
path_collection.push_back(path_copy);
}
for(int i=path_collection.size()-1; i >= 0; i--)
{
if(!PathIsDirectoryW(path_collection[i].c_str()))
if(CreateDirectoryW(path_collection[i].c_str(), NULL))
result = true;
}
return result;
};