Como abrir o windows explorer em uma pasta específica?
É necessário estar declarado ShellAPI na seção uses,
em versões unicode declare Winapi.ShellAPI;
Abaixo o código fonte da função:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| function ExecExplorer(OpenAtPath: string;
OpenWithExplorer, OpenAsRoot: Boolean): Boolean;
var
s : string;
begin
if OpenWithExplorer then
begin
if OpenAsRoot then
s := ' /e,/root,"' + OpenAtPath + '"'
else
s := ' /e,"' + OpenAtPath + '"';
end
else
s := '"' + OpenAtPath + '"';
Result := ShellExecute(Application.Handle, PChar('open'),
PChar('explorer.exe'), PChar(s), nil, SW_NORMAL) > 32;
end; |
function ExecExplorer(OpenAtPath: string;
OpenWithExplorer, OpenAsRoot: Boolean): Boolean;
var
s : string;
begin
if OpenWithExplorer then
begin
if OpenAsRoot then
s := ' /e,/root,"' + OpenAtPath + '"'
else
s := ' /e,"' + OpenAtPath + '"';
end
else
s := '"' + OpenAtPath + '"';
Result := ShellExecute(Application.Handle, PChar('open'),
PChar('explorer.exe'), PChar(s), nil, SW_NORMAL) > 32;
end;
Exemplo de uso:
1
2
3
4
5
6
7
8
9
10
| procedure TForm1.Button1Click(Sender: TObject);
begin
if (ExecExplorer('D:\Sistemas\', True, True)) then
begin
ShowMessage('Explorer aberto com sucesso!')
end
else begin
ShowMessage('Erro ao abrir o explorer!');
end;
end; |
procedure TForm1.Button1Click(Sender: TObject);
begin
if (ExecExplorer('D:\Sistemas\', True, True)) then
begin
ShowMessage('Explorer aberto com sucesso!')
end
else begin
ShowMessage('Erro ao abrir o explorer!');
end;
end;
-
InfusTec
-
10.189 views
- 0 comentários
- 30 de março de 2015
Está gostando do conteúdo? Considere pagar um cafezinho para nossa equipe!
Posts Relacionados - Continue Aprendendo