当前位置:主页>Delphi教程>文章内容
查找某目录下的所有文件
来源: 作者: 发布时间:2007-04-29  
(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;


 
上一篇:SaveComponentByFile   下一篇:我的DBTreeView--TreeView直接连接数据表
 
  相关文章
·SaveComponentByFile
·我的DBTreeView--TreeView直接连接数据
·分析DFM文件生成程序界面
·将image的图片保存为JPG格式图片方法
·在MSSQL版参与问题有所感触
·查句柄知多少
·Delphi编写组件封装asp代码的基本步骤(
·根据时间日期格式从字符串中解析日期时
·中国农历算法(delphi)
·程序字体,我们自已选
·数据补丁
·项目迭代开发手记--文件分割存储用例的
 
【关闭窗口】
推荐本站资源
最新文章