Solved

search  file in  all drive using delphi5.0

Posted on 2001-07-08
2
183 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

15 Experts available now in Live!

Get 1:1 Help Now