00 Votes

Delphi: Show Path in Windows Explorer

Question by Guest | 2014-08-18 at 20:44

I have already read the question about how to open a specific directory/path 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.

1Best Answer1 Vote

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);


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 directorys 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.
2014-08-18 at 22:36

ReplyPositive Negative

Related Topics

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.


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