Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 4138|回复: 2

Lazarus读取文件夹中所有文件的方法-DEMO

[复制链接]

该用户从未签到

发表于 2010-7-23 14:36:47 | 显示全部楼层 |阅读模式
希望对大家有用
//www.lazarus.net.cn收集整理
  1. unit RicercaFile;
  2. {$mode objfpc}{$H+}
  3. { TForm1 }
  4. {
  5. type  TFileReader = class(TFileSearcher)  public    constructor Create;    procedure OnFileFound(FileIterator: TFileIterator);  end;...constructor TFileReader.Create;begin  inherited Create;  FOnFileFound := @OnFileFound;end;...var  Searcher: TFileReader;begin  Searcher := TFileReader.Create;  Searcher.OnFileFound := @Searcher.OnFileFound;  // search the files on C:\Files directory  // search only on .txt and .html files  // recursive  // use ; as mask separator (to separate *.txt and *.html)  Searcher.Search('C:\Files','*.txt;*.html',true,';');end;}
  6. interface
  7. uses  Classes, SysUtils,  FileUtil //aggiunto per leggere i file  ;
  8. type  TFileReader = class(TFileSearcher)  public    constructor Create;    procedure OnFileFoundNew(FileIterator: TFileIterator);  end;
  9. implementationuses unit1;
  10. constructor TFileReader.Create;begin  inherited Create;   OnFileFound := @OnFileFoundNew;end;
  11. procedure TFileReader.OnFileFoundNew(FileIterator: TFileIterator);begin   Form1.Lista_File.Items.Add(FileIterator.Path + '-->' + FileIterator.FileInfo.Name + '(' + IntToStr(FileIterator.FileInfo.Attr) + ')');end;
  12. end.
  13. //--------------------------------------------------------------------------------
  14. unit Unit1; 
  15. {$mode objfpc}{$H+}
  16. interface
  17. uses  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,  StdCtrls,RicercaFile;
  18. type
  19.   { TForm1 }
  20.   TForm1 = class(TForm)    Button1: TButton;    Lista_File: TListBox;    procedure Button1Click(Sender: TObject);  private    { private declarations }  public    { public declarations }  end;
  21. var  Form1: TForm1; 
  22. implementation
  23. procedure TForm1.Button1Click(Sender: TObject);var   Searcher: TFileReader;begin     Searcher := TFileReader.Create;     // search the files on C:\Files directory     // search only on .txt and .html files     // recursive     // use ; as mask separator (to separate *.txt and *.html)      Searcher.Search('C:\Lavoro','*.mdb;*.html',true,';');end;
  24. initialization  {$I unit1.lrs}
  25. end.
复制代码
回复

使用道具 举报

该用户从未签到

发表于 2010-11-24 22:07:04 | 显示全部楼层
可惜源码的排版不太好!如果能有原文件下载就好了
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-8-3 14:04:48 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-5-3 08:30 , Processed in 0.026527 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表