Solved

search  file in  all drive using delphi5.0

Posted on 2001-07-08
2
185 Views
Last Modified: 2010-08-05
hi, i want ask about searching file in all drive in computer and showing the directory (path) about this file.

give me an example..


thank u
0
Comment
Question by:Rudy_Rai
  • 2
2 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 60 total points
ID: 6262719
To find a file on a single drive:


procedure FindFile(DirStr, thefile: string; dirlist: TStrings);
var DirInfo: TSearchRec;
    r : Integer;
begin
  if DirStr[Length(DirStr)] <> '\' then
    DirStr := DirStr + '\';
  if SetCurrentDir((DirStr)) then
  begin
    if FileSearch(thefile, DirStr) <> '' then
      dirlist.Add(DirStr);
    r := FindFirst('*.*', FaAnyfile, DirInfo);
    while r = 0 do
    begin
      if (DirInfo.Attr and faDirectory) <> 0 then
        if (DirInfo.Name <> '.') and (DirInfo.Name <> '..') then
          FindFile(DirStr + DirInfo.Name, thefile, dirlist);
      r := FindNext(DirInfo);
    end;
    FindClose(DirInfo);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FindFile('c:\', 'midas.dll', ListBox1.Items);
  Label1.Caption := IntToStr(ListBox1.Items.Count);
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6262721
To get all available drives:


procedure ListDrives(Strings: TStrings);
const BufSize = 256;
var
  Buffer                    : PChar;
  P                            : PChar;
begin
  GetMem(Buffer, BufSize);
  try
    Strings.BeginUpdate;
    try
      Strings.Clear;
      if GetLogicalDriveStrings(BufSize, Buffer) <> 0 then begin
        P := Buffer;
        while P^ <> #0 do begin
          Strings.Add(P);
          Inc(P, StrLen(P) + 1);
        end;
      end;
    finally
      Strings.EndUpdate;
    end;
  finally
    FreeMem(Buffer, BufSize);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ListDrives(ListBox2.Items);
end;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 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

16 Experts available now in Live!

Get 1:1 Help Now