查找某目录下的所有文件
2006-02-04 13:50:52 来源:WEB开发网核心提示:(1)查找指定扩展名的文件PRocedure TForm1.Button1Click(Sender: TObject);var sr: TSearchRec;begin ListBox1.Items.Clear ; if FindFirst('D:\work\*.*', faAnyFile, sr
(1)查找指定扩展名的文件
PRocedure TForm1.Button1Click(Sender: TObject);
var
sr: TSearchRec;
begin
ListBox1.Items.Clear ;
if FindFirst('D:\work\*.*', faAnyFile, sr) = 0 then
begin
repeat
if pos('.xls',lowercase(sr.Name))>0 then
ListBox1.Items.Add(sr.Name) ;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
(2)查找某目录下的所有文件,非目录
procedure TForm1.Button2Click(Sender: TObject);
var
sr: TSearchRec;
begin
ListBox1.Items.Clear ;
if FindFirst('D:\work\*.*', faAnyFile, sr) = 0 then
begin
repeat
if (sr.Attr and faDirectory)=0 then
ListBox1.Items.Add(sr.Name+ ' '+intToStr(sr.Attr)) ;
until FindNext(sr) <> 0;
FindClose(sr);
end;
showMessage(intToStr(ListBox1.Items.count));
end;
(3)查找某目录下的所有目录,包含 “.” “..”
procedure TForm1.Button2Click(Sender: TObject);
var
sr: TSearchRec;
begin
ListBox1.Items.Clear ;
if FindFirst('D:\work\*.*', faAnyFile, sr) = 0 then
begin
repeat
if (sr.Attr and faDirectory)<>0 then
ListBox1.Items.Add(sr.Name+ ' '+intToStr(sr.Attr)) ;
until FindNext(sr) <> 0;
FindClose(sr);
end;
showMessage(intToStr(ListBox1.Items.count));
end;
PRocedure TForm1.Button1Click(Sender: TObject);
var
sr: TSearchRec;
begin
ListBox1.Items.Clear ;
if FindFirst('D:\work\*.*', faAnyFile, sr) = 0 then
begin
repeat
if pos('.xls',lowercase(sr.Name))>0 then
ListBox1.Items.Add(sr.Name) ;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
(2)查找某目录下的所有文件,非目录
procedure TForm1.Button2Click(Sender: TObject);
var
sr: TSearchRec;
begin
ListBox1.Items.Clear ;
if FindFirst('D:\work\*.*', faAnyFile, sr) = 0 then
begin
repeat
if (sr.Attr and faDirectory)=0 then
ListBox1.Items.Add(sr.Name+ ' '+intToStr(sr.Attr)) ;
until FindNext(sr) <> 0;
FindClose(sr);
end;
showMessage(intToStr(ListBox1.Items.count));
end;
(3)查找某目录下的所有目录,包含 “.” “..”
procedure TForm1.Button2Click(Sender: TObject);
var
sr: TSearchRec;
begin
ListBox1.Items.Clear ;
if FindFirst('D:\work\*.*', faAnyFile, sr) = 0 then
begin
repeat
if (sr.Attr and faDirectory)<>0 then
ListBox1.Items.Add(sr.Name+ ' '+intToStr(sr.Attr)) ;
until FindNext(sr) <> 0;
FindClose(sr);
end;
showMessage(intToStr(ListBox1.Items.count));
end;
[]
赞助商链接