unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, FileCtrl, ComCtrls, ImgList, ShellAPI, Buttons;
type
TMainForm = class(TForm)
DirBox: TDirectoryListBox;
edtMask: TEdit;
lblMask: TLabel;
btnFind: TButton;
lblFoundResults: TLabel;
lbFileBox: TListView;
ImageList: TImageList;
procedure btnFindClick(Sender: TObject);
procedure lbFileBoxDblClick(Sender: TObject);
private
procedure Search(const StartDir : String; Ext : String);
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.Search(const StartDir : String; Ext : String);
var
SR, DR : TSearchRec;
Found, FoundFile : Integer;
ListItem : TListItem;
Icon : TIcon;
ExtNo : Word;
function IsDir(Value : String) : String;
begin
if Value[Length(Value)] '' then
Result := Value + '' else Result := Value;
end;
begin
Icon := TIcon.Create;
Found := FindFirst(IsDir(StartDir) + '.', faDirectory, DR);
while Found = 0 do
begin
Application.ProcessMessages;
if ((DR.Attr and faDirectory) = faDirectory) and
((DR.Name '.') and (DR.Name '..')) then
begin
FoundFile := FindFirst(IsDir(StartDir) + DR.Name + '' + Ext, faAnyFile, SR);
while FoundFile = 0 do
begin
Application.ProcessMessages;
if ((SR.Name '.') and (SR.Name '..')) then
begin
Icon.Handle := ExtractAssociatedIcon(hInstance, PCHar(IsDir(StartDir) + DR.Name + '' + SR.Name), ExtNO);
ListItem := lbFileBox.Items.Add;
ListItem.ImageIndex := ImageList.AddIcon(Icon);
ListItem.Caption := IsDir(StartDir) + DR.Name + '' + SR.Name;
ListItem.SubItems.Add(DateTimeToStr(FileDateToDateTime(SR.Time)));
ListItem.SubItems.Add(IntToStr(SR.Size) + ' B');
end;
FoundFile := FindNext(SR);
end;
FindClose(SR);
Search(IsDir(StartDir) + DR.Name, Ext);
end;
Found := FindNext(DR);
end;
FindClose(DR);
Icon.Free;
end;
procedure TMainForm.btnFindClick(Sender: TObject);
begin
lbFileBox.Clear;
ImageList.Clear;
lbFileBox.Items.BeginUpdate;
btnFind.Enabled := False;
Search(DirBox.Directory, edtMask.Text);
btnFind.Enabled := True;
lblFoundResults.Caption := 'Rezultaty poszukiwań: ' + IntToStr(lbFileBox.Items.Count) + ' znalezionych plików...';
lblFoundResults.Visible := True;
lbFileBox.Items.EndUpdate;
end;
procedure TMainForm.lbFileBoxDblClick(Sender: TObject);
begin
ShellExecute(Handle, 'open', PCHar(lbFileBox.Selected.Caption), nil, nil, SW_SHOW);
end;
end.