小编Emi*_*Emi的帖子

Delphi,删除带内容的文件夹

当我在文件夹中有子文件夹时 - 此代码不是删除文件夹...是否有任何错误?

procedure TForm.Remove(Dir: String);
var
  Result: TSearchRec; Found: Boolean;
begin
  Found := False;
  if FindFirst(Dir + '\*', faAnyFile, Result) = 0 then
    while not Found do begin
      if (Result.Attr and faDirectory = faDirectory) AND (Result.Name <> '.') AND (Result.Name <> '..') then Remove(Dir + '\' + Result.Name)
      else if (Result.Attr and faAnyFile <> faDirectory) then DeleteFile(Dir + '\' + Result.Name);
      Found := FindNext(Result) <> 0;
    end;
  FindClose(Result); RemoveDir(Dir);
end;
Run Code Online (Sandbox Code Playgroud)

windows delphi delphi-7

10
推荐指数
4
解决办法
2万
查看次数

标签 统计

delphi ×1

delphi-7 ×1

windows ×1