Спасибо за ответ. Но не могли бы вы написать пример.
Здравствуйте, kryn, Вы писали:
K>Спасибо за ответ. Но не могли бы вы написать пример.
Вот небольшой пример....
Function DeleteFolder(Path: String; DelPath: Boolean): Boolean;
Var
f: TSearchRec;
status, i: integer;
DirList: TStringList;
Begin
DirList := TStringList.Create;
status := FindFirst(Path + '*.*', faAnyFile, f); // try the first find call
while status = 0 do
with f do // keep looping while more directories
begin
if ((faDirectory and Attr) <> 0) and // is this a directory?
(Name <> '.') and (Name <> '..') // ignore backlinks
then
dirlist.Add(Path + Name + '\')
Else
If (Name <> '.') and (Name <> '..')
Then
Begin
FileSetAttr(Path + Name, faArchive);
DeleteFile(Path + Name);
End; // add it to directory list
status := FindNext(f); // see if there's another directory entry
end;
FindClose(f);
If DirList.Count = 0
Then
Begin
FileSetAttr(Path, faArchive);
RemoveDirectory(PChar(Path))
End
Else
For i := 0 To DirList.Count - 1 Do
DeleteFolder(DirList.Strings[i], True);
DirList.Free;
If DelPath
Then
Begin
FileSetAttr(Path, faArchive);
RemoveDirectory(PChar(Path));
End;
Result := true;
End;
Здравствуйте, Shtirliz, Вы писали:
S>Вот небольшой пример....
Как-то длинно... Вот покороче
procedure DeleteFolder(FolderName: string);
var
SR: TSearchRec;
Len: Integer;
begin
Len := Length(FolderName);
if FolderName[Len] = '\' then FolderName := Copy(FolderName, 1, Len-1);
if FindFirst(FolderName + '\*.*', faAnyFile, SR) = 0 then
begin
repeat
if SR.Name = '.' then Continue;
if SR.Name = '..' then Continue;
FileSetAttr(FolderName + '\' + SR.Name, SR.Attr and faDirectory);
if SR.Attr and faDirectory <> 0
then DeleteFolder(FolderName + '\' + SR.Name)
else DeleteFile(FolderName + '\' + SR.Name)
until FindNext(SR) <> 0;
FindClose(SR);
end;
RemoveDir(FolderName);
end;
... << RSDN@Home 1.1 beta 2 >>