|  | 
 
 发表于 2017-2-9 10:10:21
|
显示全部楼层 
| 复制代码uses FileCtrl, IOUtils, IdGlobalProtocols;
function GetFolderSize(vFolder: String): Int64;
var
  sr: TSearchRec;
begin
  Result := 0;
  if FindFirst(vFolder + '*.*', faAnyFile, sr) = 0 then
    repeat
      if (sr.Name <> '.') and (sr.Name <> '..') then
      begin
        Result := Result + sr.Size;
        if (sr.Attr and faDirectory) <> 0 then
          Result := Result + GetFolderSize(vFolder + sr.Name + '\');
      end;
    until FindNext(sr) <> 0;
  FindClose(sr);
end;
procedure TForm2.Button1Click(Sender: TObject);
var
  sPath: string;
begin
  if SelectDirectory('选择文件夹', '', sPath) then
  begin
    if GetFolderSize(sPath + '\') > 2147483648 then
    begin
      if MessageDlg('文件夹大小' + inttostr(GetFolderSize(sPath + '\')
        div 1024 div 1024 div 1024) + 'GB,是否删除?', mtConfirmation, [mbYes, mbNo], 0) = mrYes
      then
        TDirectory.Delete(sPath,True);
    end;
  end;
end;
 | 
 |