Resolved!
unit RicercaFile;
{$mode objfpc}{$H+}
{ TForm1 }
{
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;
}
interface
uses
Classes, SysUtils,
FileUtil //aggiunto per leggere i file
;
type
TFileReader = class(TFileSearcher)
public
constructor Create;
procedure OnFileFoundNew(FileIterator: TFileIterator);
end;
implementation
uses unit1;
constructor TFileReader.Create;
begin
inherited Create;
OnFileFound := @OnFileFoundNew;
end;
procedure TFileReader.OnFileFoundNew(FileIterator: TFileIterator);
begin
Form1.Lista_File.Items.Add(FileIterator.Path + '-->' + FileIterator.FileInfo.Name + '(' + IntToStr(FileIterator.FileInfo.Attr) + ')');
end;
end.
//--------------------------------------------------------------------------------
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls,RicercaFile;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Lista_File: TListBox;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
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;
initialization
{$I unit1.lrs}
end.