BOOL CWriteMyFile::JudgeFolderExist(CString strFolderPath)
{
BOOL bFolderExit = TRUE;
CString strFolderPathTemp = "";
int iFolderPathLength = strFolderPath.GetLength();
int iBackslashPos = -1;//"\\" positon
iBackslashPos = strFolderPath.Find("\\");
while(0 < iFolderPathLength)
{
iBackslashPos = strFolderPath.Find("\\", iBackslashPos + 1);
if (-1 == iBackslashPos)//one directory
{
strFolderPathTemp = strFolderPath;
iFolderPathLength -= strFolderPathTemp.GetLength();
//bFolderExit = JudgeFolderPathExist(strFolderPathTemp);
if(FALSE == JudgeFolderPathExist(strFolderPathTemp))//folder doesn't exist
{
CreateDirectory(strFolderPathTemp, NULL);
return TRUE;
}
}
else//many directory
{
strFolderPathTemp = strFolderPath.Left(iBackslashPos);
if(FALSE == JudgeFolderPathExist(strFolderPathTemp))//folder doesn't exist
{
CreateDirectory(strFolderPathTemp, NULL);
}
iFolderPathLength = strFolderPath.GetLength() - strFolderPathTemp.GetLength();
}
}
return TRUE;
}
BOOL CWriteMyFile::JudgeFolderPathExist(CString strFolderPath)
{
DWORD dwRet = 0;
dwRet = GetFileAttributes(strFolderPath);
if(INVALID_FILE_SIZE == dwRet)
{
return FALSE;
}
else
{
return TRUE;
}
}