Skip to content

Instantly share code, notes, and snippets.

@metametaclass
Created September 17, 2012 07:12
Show Gist options
  • Save metametaclass/3735989 to your computer and use it in GitHub Desktop.
Save metametaclass/3735989 to your computer and use it in GitHub Desktop.
BOOST_FILESYSTEM_DECL
bool create_directories(const path& p, system::error_code* ec)
{
if (p.empty() || exists(p))
{
if (!p.empty() && !is_directory(p))
{
if (ec == 0)
BOOST_FILESYSTEM_THROW(filesystem_error(
"boost::filesystem::create_directories", p,
error_code(system::errc::file_exists, system::generic_category())));
else ec->assign(system::errc::file_exists, system::generic_category());
}
return false;
}
// First create branch, by calling ourself recursively
create_directories(p.parent_path(), ec);
// Now that parent's path exists, create the directory
create_directory(p, ec);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment