Open Windows Explorer directory, select a specific file (in Delphi)

后端 未结 2 1299
天命终不由人
天命终不由人 2021-02-01 22:23

I have a procedure to open a folder in Windows Explorer that gets passed a directory path:

procedure TfrmAbout.ShowFolder(strFolder: string);
begin
   ShellExecu         


        
2条回答
  •  广开言路
    2021-02-01 23:03

    The answers at delphi.lonzu.net and swissdelphicenter offer a simpler solution to this. I've only tested it on Windows 10, 1909,, but the gist of it is:

    uses ShellApi, ...
    ...
    var
       FileName : TFileName;
    begin
      FileName := 'c:\temp\somefile.html';
    
      ShellExecute(Handle, 'OPEN', 
        pchar('explorer.exe'), 
        pchar('/select, "' + FileName + '"'), 
        nil, 
        SW_NORMAL);
    end;
    

    This is simple and easy to use. Whether it works with older versions of Windows, I don't know.

提交回复
热议问题