如何取得文件夹中文件的名称(50分)

Z

zjh2002

Unregistered / Unconfirmed
GUEST, unregistred user!
比如我想把一个文件夹中的所有BMP文件的名字加到一个LISTBOX中。因为是在KYLIX中,所以
没有FileListBox控件,只能用LISTBOX。
 
FindFirst
查找*.*
 
//我做了个例子,你看一下:
procedure TForm1.Button1Click(Sender: TObject);
var
SR : TSearchRec;
lst_Str : TStringList;
begin
lst_Str := TStringList.Create;
try
if FindFirst('c:/temp/*.bmp', faAnyFile, SR) = 0 then
begin
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr <> faDirectory) then
lst_Str.Add(SR.Name);
while FindNext(sr) = 0 do
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr <> faDirectory) then
lst_Str.Add(SR.Name);
FindClose(sr);
end;
ListBox1.Items.Text := lst_Str.Text;
finally
lst_Str.Free;
end;
end;
 
我懒得再重复写了,你去看我发过的帖子吧:)

http://www.delphibbs.com/delphibbs/dispq.asp?lid=1226436
 
多谢了,分不多,但是进来就有。
 

Similar threads

顶部