I have a form in a Delphi project. There is a button on the form. When the user clicks the button, I want it to open Windows Explorer.
What code will I need to achieve this?
File Explorer in Windows 11 helps you get the files you need quickly and easily. To check it out in Windows 11, select it on the taskbar or the Start menu, or press the Windows logo key + E on your keyboard.
To open the File Explorer window, simply press the Windows button ⊞ + E .
Press Ctrl+Shift+Esc to open the Task Manager, then right-click Windows Explorer and select "Restart" to restart Windows Explorer. On Windows 7, 8, or 10, you can also right-click the taskbar while holding Ctrl+Shift and select "Exit Explorer" to restart Windows Explorer.
Well in case you need to select some particular file in explorer I have the following function which I use
procedure SelectFileInExplorer(const Fn: string);
begin
ShellExecute(Application.Handle, 'open', 'explorer.exe',
PChar('/select,"' + Fn+'"'), nil, SW_NORMAL);
end;
and you can call it :
SelectFileInExplorer('C:\Windows\notepad.exe');
EDIT: As mentioned ShellAPI must be added to your uses list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With