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;
其实Windows也是这样做的。
还什么怎么着?
能不能说的更明确些!
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;