Today, Delphi is one of the popular desktop programming tool. There are thousand even million programmer in this world using delphi as their favorit tool. This site try to collect the examples, tips and tricks of Delphi programming. We collect, test them and redistribute the collection of delphi programming for you.

Search File in A Directory and Perform Result in TListBox

Author: admin | Category: Files, System, Tips and Tricks

//This is how we can search  any file in specific drive and directory by using a simple code
//Search a specific file like 'C:\Windows\zapotec.bmp'
//Search by using part of file name like '*.*' or 'filename.*' or 'partfilename*.*' or 'filename.*xe' etc
//For this example use Button1 (TButton) and ListBox (TListBox)
 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FileCtrl;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
var
  strFile :String;
begin
  strFile :='C:\Windows\*.*';
  //We can write file search string clause like '*.jpg' or 'zap*.bmp' or '*tec.*' etc
  ListBox1.Perform(LB_DIR,DDL_READONLY,LongInt(@strFile[1]));
end;
 
end.
 

Tags: , ,