Удалить каталог со всем содержимым
function DeleteDir(Dir: string): boolean;
var
Found: integer;
SearchRec: TSearchRec;
begin
result := false;
if IOResult <> 0 then
ChDir(Dir);
if IOResult <> 0 then
begin
ShowMessage('Не могу войти в каталог: ' + Dir);
exit;
end;
Found := FindFirst('*.*', faAnyFile, SearchRec);
while Found = 0 do
begin
if (SearchRec.name <> '.') and (SearchRec.name <> '..') then
if (SearchRec.Attr and faDirectory) <> 0 then
begin
if not DeleteDir(SearchRec.name) then
exit;
end
else
if not DeleteFile(SearchRec.name) then
begin
ShowMessage('Не могу удалить файл: ' + SearchRec.name);
exit;
end;
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
ChDir('..');
RmDir(Dir);
result := IOResult = 0;
end;
|
|