我在做文件夹拷贝时,不知如何确定文件夹的大小?(100分)

  • 主题发起人 主题发起人 amart
  • 开始时间 开始时间
A

amart

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做文件夹拷贝进度时,不知如何确定文件夹的大小?烦那位大师指点
 
//试试下面这个函数<br>function GetDirectorySize(const ADirectory: string): Integer;<br>var<br>&nbsp; Dir: TSearchRec;<br>&nbsp; Ret: integer;<br>&nbsp; Path: string;<br>begin<br>&nbsp; Result := 0;<br>&nbsp; Path := ExtractFilePath(ADirectory);<br>&nbsp; Ret := Sysutils.FindFirst(ADirectory, faAnyFile, Dir);<br>&nbsp; if Ret &lt;&gt; NO_ERROR then exit;<br>&nbsp; try<br>&nbsp; &nbsp; while ret = NO_ERROR do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; inc(Result, Dir.Size);<br>&nbsp; &nbsp; &nbsp; if (Dir.Attr in [faDirectory]) and (Dir.Name[1] &lt;&gt; '.') then<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(Result, GetDirectorySize(Path + Dir.Name + '/*.*'));<br>&nbsp; &nbsp; &nbsp; Ret := Sysutils.FindNext(Dir);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; Sysutils.FindClose(Dir);<br>&nbsp; end;<br>end;
 
抄来的:)<br><br>var<br>&nbsp; DirBytes : integer;<br><br>function TFileBrowser.DirSize(Dir:string):integer;<br>var<br>&nbsp; SearchRec : TSearchRec;<br>&nbsp; Separator : string;<br>begin<br>&nbsp; if Copy(Dir,Length(Dir),1)='/' then<br>&nbsp; &nbsp; Separator := ''<br>&nbsp; else<br>&nbsp; &nbsp; Separator := '/';<br>&nbsp; if FindFirst(Dir+Separator+'*.*',faAnyFile,SearchRec) = 0 then begin<br>&nbsp; &nbsp; if FileExists(Dir+Separator+SearchRec.Name) then begin<br>&nbsp; &nbsp; &nbsp; DirBytes := DirBytes + SearchRec.Size;<br>&nbsp; &nbsp; &nbsp; {Memo1.Lines.Add(Dir+Separator+SearchRec.Name);}<br>&nbsp; &nbsp; end else if DirectoryExists(Dir+Separator+SearchRec.Name) then begin<br>&nbsp; &nbsp; &nbsp; if (SearchRec.Name&lt;&gt;'.') and (SearchRec.Name&lt;&gt;'..') then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; DirSize(Dir+Separator+SearchRec.Name);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; while FindNext(SearchRec) = 0 do begin<br>&nbsp; &nbsp; &nbsp; if FileExists(Dir+Separator+SearchRec.Name) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; DirBytes := DirBytes + SearchRec.Size;<br>&nbsp; &nbsp; &nbsp; &nbsp; {Memo1.Lines.Add(Dir+Separator+SearchRec.Name);}<br>&nbsp; &nbsp; &nbsp; end else if DirectoryExists(Dir+Separator+SearchRec.Name) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if (SearchRec.Name&lt;&gt;'.') and (SearchRec.Name&lt;&gt;'..') then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DirSize(Dir+Separator+SearchRec.Name);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; FindClose(SearchRec);<br>end;<br>
 
接受答案了.
 

Similar threads

后退
顶部