void COperateFile::RemoveFileDirectory( LPSTR lpStrSource )
{
//RemoveDirectory(lpStrSource);
char lpSourceFolder[MAX_PATH] = "\0";
strcpy(lpSourceFolder,lpStrSource);
if (!IsEndWithBackslash(lpSourceFolder))
{
strcat(lpSourceFolder,"\\");
}
char lpSourceTempDir[MAX_PATH] = "\0";
strcpy(lpSourceTempDir,lpSourceFolder);
strcat(lpSourceTempDir,"*.*");
//search the files in the source folder
WIN32_FIND_DATA wfData;
HANDLE hFild = FindFirstFile(lpSourceTempDir,&wfData);
if (hFild == INVALID_HANDLE_VALUE ||
hFild == NULL)
{
OutputDebugString(_T("Invalid source folder.\n"));
return;
}
while(FindNextFile(hFild,&wfData))
{
wfData.cFileName;
if (!strcmp(wfData.cFileName,".."))
{continue;}
char lpTempSourceDir[MAX_PATH] = "\0";
char lpTempTargetDir[MAX_PATH] = "\0";
strcpy(lpTempSourceDir,lpSourceFolder);
strcat(lpTempSourceDir,wfData.cFileName);
if (wfData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
RemoveFileDirectory(lpTempSourceDir);
}
BOOL bOK = RemoveDirectory(lpTempSourceDir);
//If the function fails, the return value is zero
if (!bOK)
{
OutputDebugString("fail to remove the directory.\n");
}
}
}
移除空文件夹RemoveDirectory
最新推荐文章于 2023-07-26 14:59:31 发布