16,466
社区成员
发帖
与我相关
我的任务
分享
BOOL CDlgData::DeleteDirectory(char *sDirName)
{
CFileFind tempFind;
char sTempFileFind[200] ;
sprintf(sTempFileFind,"%s\*.*",sDirName);
BOOL IsFinded = tempFind.FindFile(sTempFileFind);
while (IsFinded)
{
IsFinded = tempFind.FindNextFile();
if (!tempFind.IsDots()) //文件名为"."或".."的文件夹
{
char sFoundFileName[200];
strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200));
MessageBox(sFoundFileName);
if (tempFind.IsDirectory()) //文件夹
{
char sTempDir[200];
sprintf(sTempDir,"%s\%s",sDirName,sFoundFileName);
DeleteDirectory(sTempDir);
}
else //文件
{
char sTempFileName[200];
sprintf(sTempFileName,"%s\%s",sDirName,sFoundFileName);
DeleteFile(sTempFileName);
MessageBox("删除抓拍图像成功!");
}
}
}
tempFind.Close();
if(!RemoveDirectory(sDirName))
{
return FALSE;
}
return TRUE;
}
BOOL CDlgData::DeleteDirectory(char *sDirName)
{
CFileFind tempFind;
char sTempFileFind[200] ;
sprintf(sTempFileFind,"%s\\*.*",sDirName);
BOOL IsFinded = tempFind.FindFile(sTempFileFind);
while (IsFinded)
{
IsFinded = tempFind.FindNextFile();
if (!tempFind.IsDots())
{
char sFoundFileName[200];
strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200));
if (tempFind.IsDirectory())
{
char sTempDir[200];
sprintf(sTempDir,"%s\\%s",sDirName,sFoundFileName);
DeleteDirectory(sTempDir);
}
else
{
char sTempFileName[200];
sprintf(sTempFileName,"%s\\%s",sDirName,sFoundFileName);
DeleteFile(sTempFileName);
}
}
}
tempFind.Close();
if(!RemoveDirectory(sDirName))
{
return FALSE;
}
return TRUE;
}
BOOL CDlgData::DeleteDirectory(char *sDirName)
{
CFileFind tempFind;
char sTempFileFind[200] ;
sprintf(sTempFileFind,"%s\*.*",sDirName);
BOOL IsFinded = tempFind.FindFile(sTempFileFind);
while (IsFinded)
{
IsFinded = tempFind.FindNextFile();
if (!tempFind.IsDots()) //文件名为"."或".."的文件夹
{
char sFoundFileName[200];
strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200));
MessageBox(sFoundFileName);
if (tempFind.IsDirectory()) //文件夹
{
char sTempDir[200];
sprintf(sTempDir,"%s\%s",sDirName,sFoundFileName);
//删除文件夹
SHFILEOPSTRUCT FileOp;
FileOp.fFlags = FOF_NOCONFIRMATION;
FileOp.hNameMappings = NULL;
FileOp.hwnd = NULL;
FileOp.lpszProgressTitle = NULL;
FileOp.pFrom = sTempDir;
FileOp.pTo = NULL;
FileOp.wFunc = FO_DELETE;
SHFileOperation(&FileOp);
}
else //文件
{
char sTempFileName[200];
sprintf(sTempFileName,"%s\%s",sDirName,sFoundFileName);
//删除文件夹
SHFILEOPSTRUCT FileOp;
FileOp.fFlags = FOF_NOCONFIRMATION;
FileOp.hNameMappings = NULL;
FileOp.hwnd = NULL;
FileOp.lpszProgressTitle = NULL;
FileOp.pFrom = sTempFileName;
FileOp.pTo = NULL;
FileOp.wFunc = FO_DELETE;
SHFileOperation(&FileOp);
MessageBox("删除抓拍图像成功!");
}
}
}
tempFind.Close();
if(!RemoveDirectory(sDirName))
{
return FALSE;
}
return TRUE;
}
bool DeleteDirectory(CString strDirPath)
{
int iRet;
CFileFind tempFind;
char tempFileFind[200];
if(strDirPath.GetAt(strDirPath.GetLength()-1) != '\\')
{
strDirPath += "\\";
}
sprintf(tempFileFind,"%s*.*",(LPCTSTR)strDirPath);
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[200];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
if(tempFind.IsDirectory())
{
char tempDir[200];
sprintf(tempDir,"%s%s",(LPCTSTR)strDirPath,foundFileName);
DeleteDirectory(tempDir);
}
else
{
char tempFileName[200];
sprintf(tempFileName,"%s%s",(LPCTSTR)strDirPath,foundFileName);
SetFileAttributes(tempFileName,FILE_ATTRIBUTE_NORMAL);
iRet = DeleteFile(tempFileName);
if(!iRet)
{
int err = GetLastError();
printf("error");
}
}
}
}
tempFind.Close();
if(!RemoveDirectory(strDirPath))
{
// MessageBox(0,"删除目录失败!","警告信息",MK_OK);
return false;
}
return true;
}