Navigation Menu Search PhysiologyWeb
PhysiologyWeb Logo Search PhysiologyWeb
   
— share —
Share on Facebook    Share on X    Share on LinkedIn    Share on Pinterest    Share on Reddit    Email    Copy URL

If the path points to an executable file (with the .exe extension), that application is started. For example, the following code starts Microsoft Word. Note that the path for Word may be different depending on the particular installation. If an application is properly installed, it is not necessary to include the full path to the application executable file. See below:

OpenApplicationFileFolder('C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE');
or
OpenApplicationFileFolder('WINWORD.EXE');

For a directory/folder path, the final path separator/delimiter (i.e., backslash) is not necessary. Therefore, C: and C:\ yield the same result of opening Windows File Explorer and selecting the C drive. Similarly, C:\PhysiologyWeb and C:\PhysiologyWeb\ yield the same result of opening Windows File Explorer and selecting the PhysiologyWeb directory on the C drive. The code would be the following:

OpenApplicationFileFolder('C:');
or
OpenApplicationFileFolder('C:\');

OpenApplicationFileFolder('C:\PhysiologyWeb');
or
OpenApplicationFileFolder('C:\PhysiologyWeb\');

If the path points to a non-executable file (e.g., .txt, .xlsx, .docx, etc.), the target file is opened using an application that is associated with that file type in the Windows Registry. Here is an example:

OpenApplicationFileFolder('C:\PhysiologyWeb\file.docx');

This procedure is very useful for working with directories/folders and files because it obviates the need to remember the details of the ShellExecute function (which calls the ShellExecuteA function within the Windows API). If you wish to start an application and pass one or more parameters to it (for example, to control how the application opens a file), see Open Application and Pass Parameters. For additional Delphi code for the Windows operating system, see Useful Delphi Code for the Windows Operating System.

procedure OpenApplicationFileFolder(FullPath: String);
begin
ShellExecute(Application.Handle, PChar('open'), PChar(FullPath), nil, nil, SW_SHOWNORMAL);
//references
//https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
//https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
end;




Posted: Saturday, May 27, 2023
Last updated: Tuesday, March 18, 2025
— share —
Share on Facebook    Share on X    Share on LinkedIn    Share on Pinterest    Share on Reddit    Email    Copy URL