这是delphi的例子,你看看
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;  with StringGrid1 do
  begin
    RowCount := 0;    if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then    begin
      repeat
        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;
      until FindNext(sr) <> 0;
      FindClose(sr);
    end;
  end;
end;

解决方案 »

  1.   

    用来查找子目录的函数,结果返回到一个TStringList中。function DirsInDir(Dir: string; Mask: string; var DirNames: TStringList; FullDirName: boolean = false): boolean;
    //Find Directory in Dir
    var
      FindHandle: THandle;
      FindData: Win32_Find_Data;
      procedure Add;
      var
        vDirName, vFullDirName: string;
      begin
    {    if FileExists(Dir + FindData.cFileName)
          and (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0)
            and (FindData.dwFileAttributes and FILE_ATTRIBUTE_OFFLINE = 0)
              and (FindData.dwFileAttributes and FILE_ATTRIBUTE_TEMPORARY = 0)
                then}
        vDirName := FindData.cFileName;
        vFullDirName := Dir + vDirName;
        if not((vDirName = '.') or (vDirName = '..') or (Pos(':\RECYCLED', Uppercase(vFullDirName)) > 0))
          and DirectoryExists(vFullDirName) then begin
            if FullDirName then
              DirNames.Add(vFullDirName)
            else
              DirNames.Add(vDirName);
        end;
      end;
    begin
      Result := false;
      Dir := IncludeTrailingBackSlash(Dir);
      DirNames.Clear;
      FindHandle := FindFirstFile(PChar(Dir + Mask), FindData);
      if FindHandle <> 0 then begin
        Add;
        While FindNextFile(FindHandle, FindData) do Add;
        Windows.FindClose(FindHandle);
        if DirNames.Count > 0 then Result := true;
      end;
    end;