procedure TForm1.Button1Click(Sender: TObject);var
  sr: TSearchRec;
  FileAttrs: Integer;
begin
  StringGrid1.RowCount := 1;
  if CheckBox1.Checked then
    FileAttrs := faReadOnly
  else
    FileAttrs := 0;
  if CheckBox2.Checked then
    FileAttrs := FileAttrs + faHidden;
  if CheckBox3.Checked then
    FileAttrs := FileAttrs + faSysFile;
  if CheckBox4.Checked then
    FileAttrs := FileAttrs + faVolumeID;
  if CheckBox5.Checked then    FileAttrs := FileAttrs + faDirectory;
  if CheckBox6.Checked then
    FileAttrs := FileAttrs + faArchive;
  if CheckBox7.Checked then    FileAttrs := FileAttrs + faAnyFile;  if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then  begin
    with StringGrid1 do
    begin
      if (sr.Attr and FileAttrs) = sr.Attr then
      begin
        Cells[1,RowCount-1] := sr.Name;
        Cells[2,RowCount-1] := IntToStr(sr.Size);
      end;
      while FindNext(sr) = 0 do
      begin
        if (sr.Attr and FileAttrs) = sr.Attr then
        begin
        RowCount := RowCount + 1;
        Cells[1, RowCount-1] := sr.Name;        Cells[2, RowCount-1] := IntToStr(sr.Size);
        end;
      end;
      FindClose(sr);
    end;
  end;
end;

解决方案 »

  1.   

    贱格,竟然将Delphi里面的Example 一滴不漏地copy到这里!!!
    还不加解释!!!
    够贱,韦小宝都没你贱
      

  2.   

    解释一下楼上的程序——如假包换的Delphi的Example:
    FileAttrs 是所要查找的文件的属性,你可以选择只读、隐藏、系统、目录等等属性
    重要的在path 参数中,比如你要查找的是*.exe,则应在path中写上,如c:\test\*.exe
    调用:if findfirst(path,fileattrs,sr)=0 then
           .
           .
           .
    最后,你所要的文件将在sr的属性name中取得
      filename:=sr.nameOk!就这么简单
      

  3.   

    呵呵,没那么复杂,不就是找*.exe么?
    var
      Fexe: TSearchRec;
    ........
    while findfirst(path,fileattrs,Fexe)=0  do
       ...... 要获得每个exe程序的名字,到Fexe.name中去取就是!   
      findnext(...);