//--------------------------------------------------------------------------- #include #pragma hdrstop //--------------------------------------------------------------------------- #pragma argsused #include #include #include #include #include #include BOOL IsDots(const CHAR* str) { if(strcmp(str,".") && strcmp(str,"..")) return FALSE; return TRUE; } BOOL DeleteDirectory(const CHAR* sPath) { HANDLE hFind; // file handle WIN32_FIND_DATA FindFileData; TCHAR DirPath[MAX_PATH]; TCHAR FileName[MAX_PATH]; strcpy(DirPath,sPath); strcat(DirPath,"\\*"); // searching all files strcpy(FileName,sPath); strcat(FileName,"\\"); // find the first file hFind = FindFirstFile(DirPath,&FindFileData); if(hFind == INVALID_HANDLE_VALUE) return FALSE; strcpy(DirPath,FileName); bool bSearch = true; while(bSearch) { // until we find an entry if(FindNextFile(hFind,&FindFileData)) { if(IsDots(FindFileData.cFileName)) continue; strcat(FileName,FindFileData.cFileName); if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { // we have found a directory, recurse if(!DeleteDirectory(FileName)) { FindClose(hFind); return FALSE; // directory couldn't be deleted } // remove the empty directory RemoveDirectory(FileName); strcpy(FileName,DirPath); } else { if(!DeleteFile(FileName)) { // delete the file FindClose(hFind); return FALSE; } strcpy(FileName,DirPath); } } else { // no more files there if(GetLastError() == ERROR_NO_MORE_FILES) bSearch = false; else { // some error occurred; close the handle and return FALSE FindClose(hFind); return FALSE; } } } FindClose(hFind); // close the file handle return RemoveDirectory(sPath); // remove the empty directory } WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DeleteDirectory("mods.d"); DeleteDirectory("modules"); return 0; } //---------------------------------------------------------------------------