void CopyFolder( LPCTSTR pszSrc, LPCTSTR pszDes )
{
if ((pszSrc == NULL) || (pszDes == NULL))
{
return;
}
if (_stricmp(pszSrc, pszDes) == 0)
{
return;
}
CString strSrcFilePath = pszSrc;
strSrcFilePath += _T("\\*.*");
if (!PathFileExists(pszDes))
{
CreateDirectoryFromPath(pszDes);
}
CString strDesFilePath = pszDes;
strDesFilePath += _T("\\");
CFileFind finder;
BOOL bWorking = finder.FindFile(strSrcFilePath);
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
{
continue;
}
if (finder.IsDirectory())
{
CString strDesSubPath = strDesFilePath;
strDesSubPath += finder.GetFileTitle();
CString strSrcSubPath = finder.GetFilePath();
if (_stricmp(strSrcSubPath, pszDes) != 0)
{
CopyFolder(strSrcSubPath, strDesSubPath);
}
else // des is src sub folder
{
continue;
}
}
else
{
CString strNewFileName = strDesFilePath;
strNewFileName += finder.GetFileName();
CopyFile(finder.GetFilePath(), strNewFileName, FALSE);
}
}
}
BOOL CreateDirectoryFromPath( LPCTSTR pszPath )
{
if (pszPath == NULL)
{
return FALSE;
}
int nLen = strlen(pszPath);
char szPath[_MAX_PATH];
for (int i=0; i<nLen; ++i)
{
if ((pszPath[i] == '\\') || pszPath[i] == '/')
{
szPath[i] = '\0';
if (!PathFileExists(szPath))
{
CreateDirectory(szPath, 0);
}
}
else if ((pszPath[i] == ':')) // C:\aaa\aaa
{
szPath[i] = pszPath[i];
if ((i+1) < nLen)
{
i++;
szPath[i] = pszPath[i];
continue;
}
else return FALSE;
}
szPath[i] = pszPath[i];
}
if (!PathFileExists(pszPath))
{
CreateDirectory(pszPath, 0);
}
return TRUE;
}