Fórum como buscar o endereço de um arquivo pelo nome usando delphi #559069
08/07/2016
0
Tenho um instalador com o arquivo .exe + BD access
o instalador cria um atalho do executável na area de trabalho
Problema:
preciso fazer uma rotina que enxergue o local do arquivo pelo nome para que eu possa fazer a conexão.
motivo: o BD está criptografado e eu queria fazer algo automatizado para que o o usuario nao precisasse buscar o arquivo, pois quero dixa-lo inacessivel.
como faço isso:
Algo do tipo
Busca 'nomedoarquivo' retorna 'endereço' e depois conecta o BD.
Obrigada!!!
Cristina Silva
Curtir tópico
+ 0Post mais votado
08/07/2016
uses FileCtrl;
//-----selecionando a pasta inicial-------------------------------------------//
procedure TForm1.BitBtnSelecionarDiretorioClick(Sender: TObject);
const
SELDIRHELP = 1000;
var
dir: string;
begin
if SelectDirectory(dir, [sdPerformCreate, sdPrompt], SELDIRHELP) then
edtDir.Text := dir;
end;
//-----retornando lista de pastas e subpastas---------------------------------//
procedure TForm1.GetSubDirs(const sRootDir: string; slt: TStrings);
var
srSearch: TSearchRec;
sSearchPath: string;
sltSub: TStrings;
i: Integer;
begin
sltSub := TStringList.Create;
slt.BeginUpdate;
try
sSearchPath := AddDirSeparator(sRootDir);
if FindFirst(sSearchPath + '*', faDirectory, srSearch) = 0 then
repeat
if ((srSearch.Attr and faDirectory) = faDirectory) and
(srSearch.Name <> '.') and (srSearch.Name <> '..') then
begin
slt.Add(sSearchPath + srSearch.Name);
sltSub.Add(sSearchPath + srSearch.Name);
end;
until (FindNext(srSearch) <> 0);
FindClose(srSearch);
for i := 0 to sltSub.Count - 1 do
begin
GetSubDirs(sltSub.Strings[i], slt);
Application.ProcessMessages;
end;
finally
slt.EndUpdate;
FreeAndNil(sltSub);
end;
end;
//-----adicionando barra no final do caminho da pasta-------------------------//
function TForm1.AddDirSeparator(dir: string): string;
begin
if Copy(dir, length(dir) - 1, 1) = '\' then
Result := dir
else
Result := dir + '\';
end;
//-----procurando arquivo em cada pasta da lista------------------------------//
procedure TForm1.BitBtnProcurarArquivoClick(Sender: TObject);
var
slDir: TStrings;
i: Integer;
SR: TSearchRec;
Numero: Integer;
begin
Screen.Cursor := crHourGlass;
try
slDir := TStringList.Create;
GetSubDirs(edtDir.Text, slDir);
for i := 0 to slDir.Count - 1 do
begin
Numero := FindFirst(AddDirSeparator(slDir[i]) + edtNomeArquivo.Text,
faAnyFile, SR);
if Numero = 0 then
if (SR.Attr and faDirectory) <> faDirectory then
begin
lblEndereco.Caption := 'Endereço: ' + AddDirSeparator(slDir[i]) + SR.Name;
ShowMessage(lblEndereco.Caption);
Break;
end;
end;
finally
slDir.Free;
Screen.Cursor := crDefault;
end;
end;
[img]http://projetosr.com.br/share/form_findfile.PNG[/img]
Raylan Zibel
Gostei + 1
Mais Posts
08/07/2016
Raylan Zibel
Gostei + 0
08/07/2016
Cristina Silva
Gostei + 0
08/07/2016
Cristina Silva
Gostei + 0
09/07/2016
Raylan Zibel
Deu certo?
Gostei + 0
13/07/2016
Cristina Silva
declarando SWSystem na uses
e no procedimento coloquei uma variavel caminho declarada como: shortstring;
e recebe
caminho := gsAppPath;
Pronto =)
Gostei + 1
Clique aqui para fazer login e interagir na Comunidade :)