本文整理自网络,侵删。
delphi如何计算一个目录的大小
function GetDirectorySize(const ADirectory: string): Integer;
var
Dir: TSearchRec;
Ret: integer;
Path: string;
begin
Result := 0;
Path := ExtractFilePath(ADirectory);
Ret := Sysutils.FindFirst(ADirectory, faAnyFile, Dir);
if Ret <> NO_ERROR then exit;
try
while ret=NO_ERROR do
begin
inc(Result, Dir.Size);
if (Dir.Attr in [faDirectory]) and (Dir.Name[1] <> .) then
Inc(Result, GetDirectorySize(Path + Dir.Name + \*.*));
Ret := Sysutils.FindNext(Dir);
end;
finally
Sysutils.FindClose(Dir);
end;
end;
相关阅读 >>
github上通过星级评估排名前10的最受欢迎的开源Delphi项目
Delphi leftstr 返回字符串左边指定个数的新字符(串)
更多相关阅读请进入《Delphi》频道 >>