function tform1.countd(cPath:string):longint;
 var
  sr:tsearchrec;
  at:integer;begin
 at:=sysutils.faReadOnly+sysutils.faHidden+faSysFile+faVolumeID+faDirectory+faArchive+faAnyFile;
  //result:=0;
  if findfirst(cpath,at,sr)=0 then
    begin
      repeat
        if sr.name='.' then
           continue;
        if (sr.Attr and fadirectory) = fadirectory then
            countd(sr.Name)
        else
          result:=sr.Size;
      until FindNext(sr) <> 0;
       FindClose(sr);
   end;
 end; 
  
帮我看一段程序,统计一个目录的大小 ,不知问题在哪里,得到的结果不对,顶者有分!!!!!!!!!!!

解决方案 »

  1.   

    好晕,result:=sr.Size 这个是目录大小?这个结构体变量的大小~初始化的时候设置~
      

  2.   

    countd(sr.Name) //这个是函数,不是过程
    result:=sr.Size;//这样就没有累加的过程了直接给段程序给你吧:
    function GetDirectorySize(Path: String): Integer; //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
          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;
      

  3.   

    cjianwen(空前) ( ) 信誉:100  2006-03-05 20:59:00  得分: 0  
     
     
       好晕,result:=sr.Size 这个是目录大小?这个结构体变量的大小~初始化的时候设置~sr.size是文件的大小