Solved

search  file in  all drive using delphi5.0

Posted on 2001-07-08
2
192 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 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

Technology Partners: 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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