CString GetDirectoryRemoveRightBackSlash(const CString& strPath)
{
int nIndex = strPath.ReverseFind('\\');
if (nIndex == -1)
{
return CString();
}
return strPath.Mid(0, nIndex+1);
}
BOOL CreateDirectoryWithFullPath(const CString& strDirectory)
{
if (strDirectory.IsEmpty())
{
return FALSE;
}
CString strPath = strDirectory;
if (*strDirectory.Right(1) == '\\')
{
strPath = strDirectory.Mid(0, strDirectory.GetLength()-1);
}
else
{
strPath = strDirectory;
}
if (!CreateDirectory((LPCSTR)strPath, NULL))
{
if (GetLastError() != ERROR_PATH_NOT_FOUND)
{
return FALSE;
}
else
{
if (!CreateDirectoryWithFullPath(GetDirectoryRemoveRightBackSlash(strPath))) //create remove backslash directory
{
return FALSE;
}
return CreateDirectory((LPCSTR)strPath, NULL); //create include backslash directory
}
}
return TRUE;
}