高手帮忙看看,我的某个文件夹中放的全部是一种*.bmp类型的文件,我想知道,如何通过选种这个文件夹,就可以知道里面全部*.bmp文件个数

解决方案 »

  1.   

    当选中那个文件夹后,使用FindFirst()、FindNext()来遍历该文件夹下的bmp文件,并使用计数器计算就可以了。
    其实Windows也是这样做的。
      

  2.   

    请问楼上,findFirst(),FindNext(),是delphi的函数吗?
    还什么怎么着?
    能不能说的更明确些!
      

  3.   

    procedure TMainForm.TestButtonClick(Sender: TObject);
    const
      BmpPath = 'D:\Images\Buttons\*.*';  // 这个路径下是Borland自带的bmp图片文件  function IsBmpFile(const FileName: TFileName): Boolean;
      begin
        if UpperCase(ExtractFileExt(FileName)) = '.BMP' then
          Result := True
        else
          Result := False;
      end;var
      BmpFile: TSearchRec;
      BmpFileCount: Cardinal;
    begin
      BmpFileCount := 0;
      if FindFirst(BmpPath , faAnyFile, BmpFile) = 0 then
      begin
        if IsBmpFile(BmpFile.Name) then
          Inc(BmpFileCount);
        while FindNext(BmpFile) = 0 do
        begin
          if IsBmpFile(BmpFile.Name) then
            Inc(BmpFileCount);
        end;    Edit1.Text := Format('%d', [BmpFileCount]);
        FindClose(BmpFile); // 记得要释放掉TSearchRec变量
      end
      else
        ShowMessage('Not find any "bmp" file!');
    end;