
18.05.2011, 14:32
|
 |
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
что-то типа этого:
Код:
unit Finder;
interface
uses
SysUtils, Classes;
type
TFinder = class(TComponent)
private
FMask: String;
FDirectory: String;
FAttr: Integer;
FIncludeParentPath: Boolean;
FFindList: TStringList;
procedure SetMask(const Value: String);
procedure SetDirectory(const Value: String);
procedure SetAttr(const Value: Integer);
public
property FindList: TStringList read FFindList;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Execute;
published
property Mask: String read FMask write SetMask;
property Directory: String read FDirectory write SetDirectory;
property Attr: Integer read FAttr write SetAttr;
property IncludeParentPath: Boolean read FIncludeParentPath write FIncludeParentPath;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Internet', [TFinder]);
end;
constructor TFinder.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMask:='*.*';
FDirectory:='';
FAttr:=faAnyFile;
FIncludeParentPath:=True;
FFindList:=TStringList.Create;
end;
destructor TFinder.Destroy;
begin
FFindList.Free;
inherited Destroy;
end;
procedure TFinder.SetMask(const Value: String);
begin
if Value='' then FMask:='*.*' else FMask:=Value;
end;
procedure TFinder.SetDirectory(const Value: String);
begin
if Value='' then FDirectory:='' else FDirectory:=IncludeTrailingPathDelimiter(Value);
end;
procedure TFinder.SetAttr(const Value: Integer);
begin
if Value<=0 then FAttr:=faAnyFile else FAttr:=Value;
end;
procedure TFinder.Execute;
var
ASearchRec: TSearchRec;
ADirList: TStringList;
AFileList: TStringList;
begin
FFindList.Clear;
ADirList:=TStringList.Create;
AFileList:=TStringList.Create;
try
if FindFirst(FDirectory+FMask, FAttr, ASearchRec)=0 then
begin
repeat
if (ASearchRec.Attr and faDirectory)=faDirectory then
begin
if (ASearchRec.Name<>'.') and (ASearchRec.Name<>'..') then
if FIncludeParentPath then
ADirList.Add(FDirectory+IncludeTrailingPathDelimiter(ASearchRec.Name))
else
ADirList.Add(IncludeTrailingPathDelimiter(ASearchRec.Name));
end else
begin
if (ASearchRec.Name<>'.') and (ASearchRec.Name<>'..') then
if FIncludeParentPath then
AFileList.Add(FDirectory+ASearchRec.Name)
else
AFileList.Add(ASearchRec.Name);
end;
until FindNext(ASearchRec)<>0;
end;
ADirList.Sort;
FFindList.AddStrings(ADirList);
AFileList.Sort;
FFindList.AddStrings(AFileList);
finally
AFileList.Free;
ADirList.Free;
end;
end;
end.
__________________
Пишу программы за еду.
__________________
|