/* CString to char */
char* CStringToChar(CString szStr)
{
int len = WideCharToMultiByte(CP_ACP,0,szStr,-1,NULL,0,NULL,NULL);
if (len == 0)
{
return NULL;
}
char* buffer = new char[len+1];
WideCharToMultiByte(CP_ACP,0,szStr,-1,buffer,len,NULL,NULL);
return buffer;
}
bool DeleteDirectory(string strDirName)
{
TypeConversion type;
CFileFind tempFind;
char strTempFileFind[MAX_PATH];
sprintf(strTempFileFind,"%s\\*.*", strDirName.c_str());
BOOL IsFinded = tempFind.FindFile(CString(strTempFileFind));
while (IsFinded)
{
IsFinded = tempFind.FindNextFile();
if (!tempFind.IsDots())
{
char* strFoundFileName = CStringToChar(tempFind.GetFileName().GetBuffer(MAX_PATH));
if (tempFind.IsDirectory())
{
char strTempDir[MAX_PATH];
sprintf(strTempDir,"%s\\%s", strDirName, strFoundFileName);
DeleteDirectory(strTempDir);
}
else
{
char strTempFileName[MAX_PATH];
sprintf(strTempFileName,"%s\\%s", strDirName.c_str(), strFoundFileName);
DeleteFile(CString(strTempFileName));
}
}
}
tempFind.Close();
if(!RemoveDirectory(CString(strDirName.c_str())))
{
return FALSE;
}
return TRUE;
}
MFC 删除一个文件夹下的所有文件代码
最新推荐文章于 2023-07-20 16:24:16 发布