Y
yjpya
Unregistered / Unconfirmed
GUEST, unregistred user!
各位朋友,函数如下,但下面的函数获取文件夹大小的时候,有时候准确,有时候不准确,不知道是什么原因,当获取Windows目录的容量大小的时候就不准确了,哪位朋友能帮忙改一改,可以使其无论获取什么文件夹都可以准确,即使这个文件夹里面包括隐藏文件夹或隐藏文件,谢谢。
function TGet_Size.GetDirectorySize(Path: string): Double; //eg. Path = 'c:/temp/'
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
begin
Result := Result + GetDirectorySize(Path + Sr.Name + '/');
end
else
begin
Result := Result + Sr.Size;
end;
while FindNext(sr) = 0 do
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr = faDirectory) then
begin
Result := Result + GetdirectorySize(Path + Sr.Name + '/');
end
else
begin
Result := Result + Sr.Size;
end;
FindClose(sr);
end;
end;
function TGet_Size.GetDirectorySize(Path: string): Double; //eg. Path = 'c:/temp/'
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
begin
Result := Result + GetDirectorySize(Path + Sr.Name + '/');
end
else
begin
Result := Result + Sr.Size;
end;
while FindNext(sr) = 0 do
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr = faDirectory) then
begin
Result := Result + GetdirectorySize(Path + Sr.Name + '/');
end
else
begin
Result := Result + Sr.Size;
end;
FindClose(sr);
end;
end;