findfisrt
findnext
findclose看一下帮助,很简单的

解决方案 »

  1.   

    //==============================================================================
    //统计指定目录下指定类型文件数量(包括子目录)**********************************
    //==============================================================================
    function GetFileCount(DirName,FileType: string): Integer;
    var DirInfo: TSearchRec;
        DosError: Integer;
    begin
      Result := 0;
      DosError := FindFirst(DirName+'\*.*', FaAnyfile, DirInfo);
      while DosError=0 do
      begin
        if ((DirInfo.Attr and FaDirectory)=faDirectory) and (DirInfo.Name<>'.') and (DirInfo.Name<>'..')
        then Result := Result + GetFileCount(DirName + '\' + DirInfo.Name, FileType);
        {$IF DEFINED(WIN32) AND DECLARED(UsingVCL)}
        if ((DirInfo.Attr and FaDirectory)<>FaDirectory) and ((DirInfo.Attr and FaVolumeID)<>FaVolumeID)
        {$ELSE}
        if ((DirInfo.Attr and FaDirectory)<>FaDirectory)
        {$IFEND}
        then if Trim(FileType)='*.*'
             then Inc(Result)
             else if Pos(UpperCase(Copy(FileType,Pos('*',FileType)+1,Length(FileType)-1)),UpperCase(DirInfo.Name))>0
                  then Inc(Result);
        DosError := FindNext(DirInfo);
      end;
      SysUtils.FindClose(DirInfo);
    end;