Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.StdCtrls, Vcl.Dialogs, Vcl.ExtCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Edit1: TEdit;
- Memo1: TMemo;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- function FindFile(const FileName, SearchPath: string): string;
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- function TForm1.FindFile(const FileName, SearchPath: string): string;
- var
- SR: TSearchRec;
- FoundPath: string;
- begin
- FoundPath := '';
- if FindFirst(SearchPath + FileName, faAnyFile, SR) = 0 then
- begin
- FoundPath := SearchPath + FileName;
- end;
- FindClose(SR);
- if FoundPath = '' then
- begin
- if FindFirst(SearchPath + '*.*', faDirectory, SR) = 0 then
- begin
- repeat
- if ((SR.Attr and faDirectory) <> 0) and (SR.Name <> '.') and (SR.Name <> '..') then
- begin
- FoundPath := FindFile(FileName, SearchPath + SR.Name + '\');
- if FoundPath <> '' then Break;
- end;
- until FindNext(SR) <> 0;
- end;
- FindClose(SR);
- end;
- Result := FoundPath;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var
- FileName, SearchPath, FoundPath: string;
- begin
- FileName := Edit1.Text;
- SearchPath := 'C:\';
- FoundPath := FindFile(FileName, SearchPath);
- if FoundPath <> '' then
- Memo1.Lines.Add('O arquivo ' + FileName + ' foi encontrado em ' + FoundPath)
- else
- Memo1.Lines.Add('O arquivo ' + FileName + ' não foi encontrado.');
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement