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
I'm modifying an old Windows CE app, and this is what I'm planning to use. Should work in Windows CE, too. This is actually recursive, too:
static void createPath(const CString& p)
{
// only create directories that don't exist
if (::GetFileAttributes(p) == INVALID_FILE_ATTRIBUTES)
{
// check if our parent needs to be created, too...
int i = p.ReverseFind('\\');
if (i > 0)
{
// ...yes, create the parent (recursively)
createPath(p.Left(i));
}
// finally, actually create the directory in p
::CreateDirectory(p, NULL);
}
}