22 Votes

Delphi: Show Path in Windows Explorer

Question by Guest | Last update on 2022-07-27 | Created on 2014-08-18

I have already read the question about how to open a specific directory, path or folder in the Windows Explorer using Lazarus. However, when using Delphi, there is no function called OpenDocument available that is used there.

Does someone have any solution that is also working in Delphi? I would like to use Lazarus for this purpose, but at our school, we are forced to implement it in Delphi.

ReplyPositiveNegative
3Best Answer3 Votes

In Delphi, you can use the function ShellExecute for this purpose. Although this function does not only have one parameter like OpenDocument, it also can open the Explorer:

ShellExecute(Application.Handle, nil, 
'C:\Folder\Folder', nil, nil, SW_SHOWNORMAL);

Or:

ShellExecute(Application.Handle, 'explore', 
'C:\Folder\Folder', nil, nil, SW_SHOWNORMAL); 

In the first example, we set the second parameter to "nil" making Windows to select the default program for file paths. In the second case, we are passing "explore" making Windows to use the Windows Explorer in each case to open the directory (a user may also have set another default application for directories on his system).

And here is another example using a variable:

APath := 'C:\Folder\Folder';

ShellExecute(Application.Handle, nil, 
PChar(APath), nil, nil, SW_SHOWNORMAL);

Important: The unit ShellApi has to be included.
Last update on 2022-07-27 | Created on 2014-08-18

ReplyPositive Negative
Reply

Related Topics

Delphi: System-Wide HotKey

Tutorial | 1 Comment

VirtualBox: Change Date and Time

Tutorial | 10 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.