如何找出跟应用程序同一路径下的所有文件夹的名称
(注意不是文件夹里面的文件)

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
        sr : TSearchRec;
        FileAttrs: Integer;
    begin
        FileAttrs := 0;
        //只查找文件夹
        FileAttrs := FileAttrs + faDirectory;
        if FindFirst(ExtractFilePath(Application.ExeName)+'*.*',FileAttrs,sr)=0 then
        begin
            repeat
                if (sr.Attr and FileAttrs)=sr.Attr then
                begin
                    Memo1.Lines.Add(sr.Name);
                end;
            until FindNext(sr) <> 0;
            FindClose(sr);
        end;
    end;end.