Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

search  file in  all drive using delphi5.0

Posted on 2001-07-08
2
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 240 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

609 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