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;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Edit1: TEdit;
- FileOpenDialog1: TFileOpenDialog;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- function FindFileInSubFolders(const FolderName, FileName: string): Boolean;
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- function TForm1.FindFileInSubFolders(const FolderName, FileName: string): Boolean;
- var
- SearchRec: TSearchRec;
- begin
- if FindFirst(FolderName + FileName + '.*', faAnyFile, SearchRec) = 0 then
- begin
- Result := True;
- FindClose(SearchRec);
- end
- else if FindFirst(FolderName + '*.*', faDirectory, SearchRec) = 0 then
- begin
- Result := False;
- repeat
- if ((SearchRec.Attr and faDirectory) <> 0) and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
- if FindFileInSubFolders(FolderName + SearchRec.Name + '\', FileName) then
- begin
- Result := True;
- Break;
- end;
- until FindNext(SearchRec) <> 0;
- FindClose(SearchRec);
- end
- else
- Result := False;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var
- FileName, FolderName: string;
- Found: Boolean;
- begin
- FileName := Edit1.Text;
- if FileOpenDialog1.Execute then
- begin
- FolderName := ExtractFilePath(FileOpenDialog1.FileName);
- Found := FindFileInSubFolders(FolderName, FileName);
- if Found then
- ShowMessage('O arquivo ' + FileName + ' foi encontrado na pasta selecionada ou em suas subpastas.')
- else
- ShowMessage('O arquivo ' + FileName + ' não foi encontrado na pasta selecionada nem em suas subpastas.');
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement