void DeleteDirFiles(char * lpPath)
{
char szFind[MAX_PATH], szFile[MAX_PATH];
WIN32_FIND_DATAA FindFileData;
strcpy(szFind, lpPath);
strcat(szFind, "*.*");
HANDLE hFind = ::FindFirstFileA(szFind, &FindFileData);
if (INVALID_HANDLE_VALUE == hFind)
return;
while (TRUE)
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (FindFileData.cFileName[0] != '.')
{
strcpy(szFile, lpPath);
strcat(szFile, "");
strcat(szFile, FindFileData.cFileName);
DeleteDirFiles(szFile);
}
}
else
{
string file;
file.append(lpPath);
file.append(FindFileData.cFileName);
if (!DeleteFileA(file.c_str()))
{
char clog[MAX_PATH] = { 0 };
sprintf(clog, "delete file failed: %d, %s", GetLastError, FindFileData.cFileName);
Log(clog);
}
}
if (!FindNextFileA(hFind, &FindFileData))
break;
}
FindClose(hFind);
}