MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / DeleteDirectory

Function DeleteDirectory

sourcecommon/utils.cpp:233–297  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

231}
232//---------------------------------------------------------------------------
233bool DeleteDirectory(char * szPath, bool bDelTopDir)
234{
235 int t = strlen(szPath);
236 if( t<3 ) return false;
237 if( szPath[t-1]!='\\' ) strcat(szPath, "\\");
238
239 // ������ ��� ����� *.* � ���������� szPath
240 HANDLE handle;
241 WIN32_FIND_DATA FD;
242 char start[MN];
243 wsprintf(start, "%s*.*", szPath);
244 bool bRetVal = true;
245
246 handle = FindFirstFile(start, &FD);
247 if( handle != INVALID_HANDLE_VALUE )
248 do
249 {
250 wsprintf(start, "%s%s", szPath, FD.cFileName);
251 if( FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
252 {
253 // !="." && !=".."
254 if( strcmpi(FD.cFileName, ".") && strcmpi(FD.cFileName, "..") )
255 {
256 if( !DeleteDirectory(start) )
257 bRetVal = false;
258 }
259 }
260 else
261 {
262 if( !::DeleteFile(start) )
263 {
264 // ���� ���������� ������� "������ ��� ������" - ������ ��� � ��������� �����
265 DWORD a = ::GetFileAttributes(start);
266 if( a==0xFFFFFFFF )
267 bRetVal = false;
268 else
269 {
270 if( a & FILE_ATTRIBUTE_READONLY )
271 {
272 if( ::SetFileAttributes(start, a^FILE_ATTRIBUTE_READONLY) )
273 {
274 if( !::DeleteFile(start) )
275 bRetVal = false;
276 }
277 else
278 bRetVal = false;
279 }
280 else
281 bRetVal = false;
282 }
283 }
284 }
285 } while( FindNextFile(handle, &FD) );
286 FindClose(handle);
287
288 if( bDelTopDir )
289 {
290 Sleep(500); // ����� �������� ���� ������ ���������� ������-�� �� ��������� � XP !

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected