[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

search  file in  all drive using delphi5.0

Posted on 2001-07-08
2
Medium Priority
?
198 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 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