Удаление содержимого каталога
Автор: demon-777
WEB-сайт: http://delphibase.endimus.com
{ **** UBPFD *********** by delphibase.endimus.com ****
>> Удаление содержимого каталога
Зависимости: Windows, SysUtils, Classes, Masks
Автор: demon-777, demon-777@yandex.ru, Питер
Copyright: Dimka Maslov
Дата: 26 мая 2002 г.
***************************************************** }
procedure DeleteFiles(Path: string);
var
Mask: string;
SearchRec: TSearchRec;
FindResult: Integer;
List: TStringList;
i: Integer;
begin
Mask := ExtractFileName(Path);
if Mask = '' then
Mask := '*.*';
Path := ExtractFilePath(Path);
if Path = '' then
Path := IncludeTrailingBackslash(GetCurrentDir);
List := TStringList.Create;
try
FindResult := FindFirst(Path + '*.*', faAnyFile, SearchRec);
try
while FindResult = 0 do
with SearchRec do
begin
if ((Attr and faDirectory) = 0) and MatchesMask(Name, Mask) then
List.Add(Name);
FindResult := FindNext(SearchRec);
end;
for i := 0 to List.Count - 1 do
DeleteFile(Path + List[i]);
finally
FindClose(SearchRec);
end;
finally
List.Free;
end;
end;
|