friberg
asked on
Search for a file (component or API function)
I need a component or API function that can search for a file on local hard drives. I know how to do this non-visually, but I want the Win95/98 animated search icon to appear as the file is being searched for.
Any help appreciated.
Any help appreciated.
ASKER
Thanks, but I need to catch the complete path of the file in the application, so that I can store it in a string and use it in the code. And I also need to specify (in the application) which file to search for.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hmmm.. Your question is somehow a bit easy to misunderstand! this is the only API call doing this.
The animated cursor thing just shows you what's is beeing done while it, but if you want it showing while searching, do like Wang shows you to a Form2 while you can set it up as a dialog form showing at screen center.
Then this works perfectly:
procedure FindFilesInDir(var List: TStringList; Directory, SearchName: String);
var
S: TSearchRec;
I: Integer;
begin
I := FindFirst(Directory+'\*.*' ,faAnyFile ,S);
While I=0 do
Begin
If (S.name<>'.') AND (S.Name<>'..') then
Begin
if pos(SearchName,S.Name)>0 then List.Add(Directory+'\'+S.N ame);
If (S.Attr AND faDirectory)>0 then
FindFilesInDir(List,Direct ory+'\'+S. Name,Searc hName);
End;
I:= FindNext(S);
End;
FindClose(S);
End;
procedure TForm1.Button1Click(Sender : TObject);
var
List: TStringList;
begin
List:= TStringList.Create;
Form2.Show;
Form2.Animate1.Active:= True;
FindFilesInDir(List,'C:',' .zip');
Memo1.Lines.AddStrings(Lis t);
List.free;
Form2.Animate1.Active:= False;
Form2.Close;
end;
The animated cursor thing just shows you what's is beeing done while it, but if you want it showing while searching, do like Wang shows you to a Form2 while you can set it up as a dialog form showing at screen center.
Then this works perfectly:
procedure FindFilesInDir(var List: TStringList; Directory, SearchName: String);
var
S: TSearchRec;
I: Integer;
begin
I := FindFirst(Directory+'\*.*'
While I=0 do
Begin
If (S.name<>'.') AND (S.Name<>'..') then
Begin
if pos(SearchName,S.Name)>0 then List.Add(Directory+'\'+S.N
If (S.Attr AND faDirectory)>0 then
FindFilesInDir(List,Direct
End;
I:= FindNext(S);
End;
FindClose(S);
End;
procedure TForm1.Button1Click(Sender
var
List: TStringList;
begin
List:= TStringList.Create;
Form2.Show;
Form2.Animate1.Active:= True;
FindFilesInDir(List,'C:','
Memo1.Lines.AddStrings(Lis
List.free;
Form2.Animate1.Active:= False;
Form2.Close;
end;
ASKER
Thanks, I'll try that.
The following example demonstrates using DDE to execute Explorer's
find file dialog. The example opens the dialog in the Directory
"C:\Download".
procedure TForm1.Button1Click(Sender
begin
with TDDEClientConv.Create(Self
ConnectMode := ddeManual;
ServiceApplication := 'explorer.exe';
SetLink( 'Folders', 'AppProperties');
OpenLink;
ExecuteMacro('[FindFolder(
CloseLink;
Free;
end;
end;