Thread View: comp.lang.pascal.delphi.misc
4 messages
4 total messages
Started by Chow Hoi Ka, Eric
Mon, 24 May 1999 00:00
How to search file ?
Author: Chow Hoi Ka, Eric
Date: Mon, 24 May 1999 00:00
Date: Mon, 24 May 1999 00:00
9 lines
1064 bytes
1064 bytes
Hello, How to search a certain file(*.*, *.dat, etc.) in local drives ??? Would you please to give me an simple example ???? Best regards, Eric
Re: How to search file ?
Author: Stephan Marais
Date: Sun, 23 May 1999 00:00
Date: Sun, 23 May 1999 00:00
18 lines
1169 bytes
1169 bytes
Hi Eric, I do not have an example, but have a look at the help for FindFirst and FindNext. There are some examples included. regards Stephan "Chow Hoi Ka, Eric" wrote: > Hello, > > How to search a certain file(*.*, *.dat, etc.) in local drives ??? > > Would you please to give me an simple example ???? > > Best regards, > Eric
Re: How to search file ?
Author: Dirk Claessens
Date: Sun, 23 May 1999 00:00
Date: Sun, 23 May 1999 00:00
117 lines
4079 bytes
4079 bytes
Chow Hoi Ka, Eric heeft geschreven in bericht
<374833A0.88F127CD@sftw.umac.mo>...
:Hello,
:
:How to search a certain file(*.*, *.dat, etc.) in local drives ???
:
:Would you please to give me an simple example ????
:
:
Eric,
See code below. It was posted some time ago by Peter Below of TeamB.
Regards,
Dirk Claessens
______________________________________________
E-mail will bounce back, unless directed to:
dirk DOT claessens AT village DOT uunet DOT be
______________________________________________
=================REPOST=======================================
> Is it possible to search through more than one drive and many
> directories to locate a file? Lets just say I'm looking for the file
> "text.txt" and It may be in either drive c or drive e.
> Could someone please provide an example to accomplish this?
>
Nick,
i happen to have this code snippet around:
recursively scanning all drives
{ excerpt from form declaration, form has a listbox1 for the
results, a label1 for progress, a button2 to start the scan,
an edit1 to get the search mask from, a button3 to stop
the scan. }
private
{ Private declarations }
FScanAborted: Boolean;
public
{ Public declarations }
Function ScanDrive( root, filemask: String; hitlist: TStrings ):
Boolean;
Function TForm1.ScanDrive( root, filemask: String; hitlist: TStrings ):
Boolean;
Function ScanDirectory( Var path: String ): Boolean;
Var
SRec: TSearchRec;
pathlen: Integer;
res: Integer;
Begin
label1.caption := path;
pathlen:= Length(path);
{ first pass, files }
res := FindFirst( path+filemask, faAnyfile, SRec );
If res = 0 Then
try
While res = 0 Do Begin
hitlist.Add( path + SRec.Name );
res := FindNext(SRec);
End;
finally
FindClose(SRec)
end;
Application.ProcessMessages;
Result := not (FScanAborted or Application.Terminated);
If not Result Then Exit;
{second pass, directories}
res := FindFirst( path+'*.*', faDirectory, SRec );
If res = 0 Then
try
While (res = 0) and Result Do Begin
If ((Srec.Attr and faDirectory) = faDirectory) and
(Srec.name[1] <> '.')
Then Begin
path := path + SRec.name + '\';
Result := ScanDirectory( path );
SetLength( path, pathlen );
End;
res := FindNext(SRec);
End;
finally
FindClose(SRec)
end;
End;
Begin
FScanAborted := False;
Screen.Cursor := crHourglass;
try
Result := ScanDirectory(root);
finally
Screen.Cursor := crDefault
end;
End;
procedure TForm1.Button2Click(Sender: TObject);
Var
ch: Char;
root: String;
Begin
root := 'C:\';
For ch := 'A' to 'Z' Do Begin
root[1] := ch;
Case GetDriveType( Pchar( root )) Of
DRIVE_FIXED, DRIVE_REMOTE:
If not ScanDrive( root, edit1.text, listbox1.items ) Then
Break;
End;
End;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin // aborts scan
fScanAborted := True;
end;
Peter Below (TeamB) 100113.1101@compuserve.com)
No e-mail responses, please, unless explicitely requested!
Re: How to search file ?
Author: Earl F. Glynn
Date: Mon, 24 May 1999 00:00
Date: Mon, 24 May 1999 00:00
15 lines
1474 bytes
1474 bytes
Chow Hoi Ka, Eric <d951686@sftw.umac.mo> wrote in message news:374833A0.88F127CD@sftw.umac.mo... > How to search a certain file(*.*, *.dat, etc.) in local drives ??? Look for links with examples under "FindFirst/FindNext/FIndClose" and "Recursive Search/Delete" at http://www.efg2.com/lab/library/delphi/IO/Directories.htm efg _________________________________ efg's Computer Lab: http://www.efg2.com/lab Delphi Books: http://www.efg2.com/lab/TechBooks/Delphi.htm Earl F. Glynn E-Mail: EarlGlynn@att.net Overland Park, KS USA
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads