删除操作的功能实现函数
bool DeleteFolder(const TCHAR* pszFolderPath)
{
if(taccess(pszFolderPath,0)==0)
{
if(!DeleteEntireDir(pszFolderPath))
{
return false;
}
}
return true;
}
bool DeleteEntireDir(const TCHAR * sPath,bool bDelDir/*=true*/)
{
CFileFind ff;
BOOL bFound;
bFound = ff.FindFile(CString(sPath) + "\\*.*");
while(bFound)
{
bFound = ff.FindNextFile();
CString sFilePath = ff.GetFilePath();
if(ff.IsDirectory())
{
if(!ff.IsDots())
{
DeleteEntireDir(sFilePath);
}
}
else
{
if(ff.IsReadOnly())
{
SetFileAttributes(sFilePath, FILE_ATTRIBUTE_NORMAL);
}
DeleteFile(sFilePath);
}
}
ff.Close();
if (bDelDir)
{
SetFileAttributes(sPath, FILE_ATTRIBUTE_NORMAL); //设置文件夹的属性
RemoveDirectory(sPath);
}
return true;
}
最后直接调用函数DeleteFolder就可以了。这里的输入参数是文件夹的路径。