对单独目录可以,但是对盘符似乎出问题,统计不准。
uses ShellApi;
function GetDirectorySize(Path: string): Int64;
var
SR: TSearchRec;
begin
Result := 0;
if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
begin
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr = faDirectory) then
Result := Result + GetDirectorySize(Path + Sr.Name + '/')
else
Result := Result + Sr.Size;
while FindNext(sr) = 0 do
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr = faDirectory) then
Result := Result + GetdirectorySize(Path + Sr.Name + '/')
else
Result := Result + Sr.Size;
FindClose(sr);
end;
end;