Solved

Search files in whole HD

Posted on 2001-07-27
4
182 Views
Last Modified: 2010-04-06
How can I do a search for a file in whole hard disk.
thanks a lot.
Headry
0
Comment
Question by:Headry
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6329263
hi,
this will search all drives and return all found .mp3 files into combobox with path:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure GatherFiles(Const Lines: TStrings; Const Dir,Match: String);
var
  Rec: TSearchRec;
  Found: Integer;
Begin
  Found:= FindFirst(Dir+'\'+Match, faAnyFile, Rec);
  While Found = 0 do
  begin
    If (Rec.Attr AND faDirectory) = 0 Then Lines.Add(Dir+'\'+Rec.Name);
    Found := FindNext(Rec);
    Application.processmessages;
  End;
  FindClose(Rec);
  Found:= FindFirst(Dir+'\*.*', faAnyFile, Rec);
  While Found = 0 do
  begin
    If ((Rec.Attr AND faDirectory)>0) AND
       (Rec.Name<>'.') AND
       (Rec.Name<>'..') Then GatherFiles(Lines,Dir+'\'+Rec.Name,Match);
    Found := FindNext(Rec);
  End;
  FindClose(Rec);
End;

procedure TForm1.Button1Click(Sender: TObject);
var
b : byte;
drivenum  : set of 0..25;
driveletter : string;
const
drivetype : array [0..6] of string = ('CD-Rom','Local Drive','Floppy Disk',
'Network Drive','RAM-Disk','Unknown','Unknown');
 begin
  integer(drivenum):=GetLogicalDrives;
   for b := 0 to 25 do
    if b in drivenum then
   begin
    driveLetter:=char(b + ord('A'));
     GatherFiles(ComboBox1.Items,driveletter+':','*.mp3');
     application.processmessages;
      end;
  If ComboBox1.Items.Count>0 Then
   ComboBox1.Text:= ComboBox1.Items[0];
  ShowMessage('Found '+IntToStr(ComboBox1.Items.Count)+' matching files.');
end;

end.



or on the button click can just do
GatherFiles(ComboBox1.Items,'C:','*.dll');
to only search c drive for .dlls for instance.
0
 
LVL 1

Expert Comment

by:trex_fire
ID: 6330345
Never heard of jedi project?

Lot of great code and free, i use it a lot and it solves a lot of problems...  http://www.delphi-jedi.org/

post me if you need any help on that

T-Rex
trex_fire@hotmail.com
0
 

Author Comment

by:Headry
ID: 6330352
thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks!!!
Finaly!
you`re good. For a hobby, you know much!
thanks again!
0
 

Author Comment

by:Headry
ID: 6330360
thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks!!!
Finaly!
you`re good. For a hobby, you know much!
thanks again!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now