procedure TForm1.Button1Click(Sender: TObject); var s:String; begin s:='d:\a\*.mpg'; SendMessage(ListBox1.Handle,LB_DIR,DDL_ARCHIVE or DDL_HIDDEN or DDL_SYSTEM or DDL_READWRITE,Integer(s));end;
上面那个比较简单也可以使用findfrist,findnext配合递归做个函数。
一次给你弄了吧。WINXP+D7下测试通过 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; ListBox1: TListBox; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public procedure Findds(AStrings: TStrings; APath, Sourfile: string); end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);//方法一 var s:String; begin s:='d:\a\*.rar'; SendMessage(ListBox1.Handle,LB_DIR,DDL_ARCHIVE or DDL_HIDDEN or DDL_SYSTEM or DDL_READWRITE,Integer(s));end;procedure TForm1.Button2Click(Sender: TObject); begin Findds(Memo1.Lines,'d:\a\','*.rar'); end;procedure TForm1.Findds(AStrings: TStrings; APath, Sourfile: string);//方法二 var FSearchRec : TSearchRec; FindResult : integer; TmpList:TStringList; i : integer; function IsDirNot(A : string) : boolean; begin Result := (a = '.') or (a = '..'); end; begin try TmpList:=TStringList.Create; TmpList.Clear; FindResult := FindFirst(Apath+Sourfile,faDirectory,FSearchRec); while FindResult = 0 do begin if ((FSearchRec.Attr and fadirectory) = faDirectory) then begin if not IsDirNot(FSearchRec.Name) then begin tmplist.Add(apath+FSearchRec.Name); Findds(AStrings, APath + FSearchRec.Name + '\',Sourfile); end; end else tmplist.Add(apath+FSearchRec.Name); FindResult := FindNext(FSearchRec); end; for i := 0 to TmpList.Count -1 do AStrings.Add(TmpList.Strings[i]); TmpList.Free; finally FindClose(FSearchRec); end; end; end.
var
s:String;
begin
s:='d:\a\*.mpg';
SendMessage(ListBox1.Handle,LB_DIR,DDL_ARCHIVE or DDL_HIDDEN or DDL_SYSTEM or DDL_READWRITE,Integer(s));end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
ListBox1: TListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
procedure Findds(AStrings: TStrings; APath, Sourfile: string);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);//方法一
var
s:String;
begin
s:='d:\a\*.rar';
SendMessage(ListBox1.Handle,LB_DIR,DDL_ARCHIVE or DDL_HIDDEN or DDL_SYSTEM or DDL_READWRITE,Integer(s));end;procedure TForm1.Button2Click(Sender: TObject);
begin Findds(Memo1.Lines,'d:\a\','*.rar');
end;procedure TForm1.Findds(AStrings: TStrings; APath, Sourfile: string);//方法二
var
FSearchRec : TSearchRec;
FindResult : integer;
TmpList:TStringList;
i : integer;
function IsDirNot(A : string) : boolean;
begin
Result := (a = '.') or (a = '..');
end;
begin
try
TmpList:=TStringList.Create;
TmpList.Clear;
FindResult := FindFirst(Apath+Sourfile,faDirectory,FSearchRec);
while FindResult = 0 do
begin
if ((FSearchRec.Attr and fadirectory) = faDirectory) then
begin
if not IsDirNot(FSearchRec.Name) then begin
tmplist.Add(apath+FSearchRec.Name); Findds(AStrings, APath + FSearchRec.Name + '\',Sourfile);
end;
end else tmplist.Add(apath+FSearchRec.Name);
FindResult := FindNext(FSearchRec);
end;
for i := 0 to TmpList.Count -1 do
AStrings.Add(TmpList.Strings[i]);
TmpList.Free;
finally
FindClose(FSearchRec);
end;
end;
end.
procedure TForm1.Findds(AStrings: TStrings; APath, Sourfile: string);//方法二---------------------------------不厚道啊
你说个法一就可以了啊
全说出来
叫我们怎么混啊:(