0

I have to create a directory structure recursively in C

Currently I am using the following logic in c++:

void createDirectoryRecursively(std::wstring path)
{
  unsigned int pos = 0;
  do
  {
    pos = path.find_first_of(L"\\/", pos + 1);
    CreateDirectory(path.substr(0, pos).c_str(), NULL);
  } while (pos != std::string::npos);
}

How can I create a directory structure recursively in a single API functions call in windows by providing only the path I need?

Mathieu
  • 8,840
  • 7
  • 32
  • 45
  • 3
    you can use [`SHCreateDirectoryEx`](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762131(v=vs.85).aspx) – RbMm Feb 28 '18 at 12:10
  • 1
    First sentence of the [documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762131.aspx) you linked to: *"This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable in subsequent versions of Windows."* – IInspectable Feb 28 '18 at 12:32
  • Create the directories one level at a time – David Heffernan Feb 28 '18 at 12:43

0 Answers0