www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Open a folder with explorer.exe

reply bauss <jacobbauss gmail.com> writes:
I cannot figure out how to get spawnProcess working with 
explorer.exe on Windows.

Been trying to call it like:

```
spawnProcess(["explorer.exe", path]);
```

But it only opens explorer.exe in the documents path and not the 
path given.

I've tried to set the working directory too and it doesn't work 
either.

Can anyone help me? All I want to do is open a specific folder in 
explorer.exe given a specific path.
Dec 28 2024
next sibling parent bauss <jacobbauss gmail.com> writes:
On Saturday, 28 December 2024 at 18:55:08 UTC, bauss wrote:
 I cannot figure out how to get spawnProcess working with 
 explorer.exe on Windows.

 Been trying to call it like:

 ```
 spawnProcess(["explorer.exe", path]);
 ```

 But it only opens explorer.exe in the documents path and not 
 the path given.

 I've tried to set the working directory too and it doesn't work 
 either.

 Can anyone help me? All I want to do is open a specific folder 
 in explorer.exe given a specific path.
Still haven't found a solution. Ended up calling cmd.exe and opening the folder from there.
Dec 28 2024
prev sibling next sibling parent reply Jordan Wilson <wilsonjord gmail.com> writes:
On Saturday, 28 December 2024 at 18:55:08 UTC, bauss wrote:
 I cannot figure out how to get spawnProcess working with 
 explorer.exe on Windows.

 Been trying to call it like:

 ```
 spawnProcess(["explorer.exe", path]);
 ```

 But it only opens explorer.exe in the documents path and not 
 the path given.

 I've tried to set the working directory too and it doesn't work 
 either.

 Can anyone help me? All I want to do is open a specific folder 
 in explorer.exe given a specific path.
This may achieve what you want: `spawnProcess(["powershell", "invoke-item", "-path", path]);` Thanks, Jordan
Dec 28 2024
parent reply bauss <jacobbauss gmail.com> writes:
On Saturday, 28 December 2024 at 19:23:39 UTC, Jordan Wilson 
wrote:
 On Saturday, 28 December 2024 at 18:55:08 UTC, bauss wrote:
 I cannot figure out how to get spawnProcess working with 
 explorer.exe on Windows.

 Been trying to call it like:

 ```
 spawnProcess(["explorer.exe", path]);
 ```

 But it only opens explorer.exe in the documents path and not 
 the path given.

 I've tried to set the working directory too and it doesn't 
 work either.

 Can anyone help me? All I want to do is open a specific folder 
 in explorer.exe given a specific path.
This may achieve what you want: `spawnProcess(["powershell", "invoke-item", "-path", path]);` Thanks, Jordan
Yeah I ended up doing something similar, but with cmd.
Dec 28 2024
parent evilrat <evilrat666 gmail.com> writes:
On Saturday, 28 December 2024 at 19:25:48 UTC, bauss wrote:
 On Saturday, 28 December 2024 at 19:23:39 UTC, Jordan Wilson 
 wrote:
 On Saturday, 28 December 2024 at 18:55:08 UTC, bauss wrote:
 I cannot figure out how to get spawnProcess working with 
 explorer.exe on Windows.

 Been trying to call it like:

 ```
 spawnProcess(["explorer.exe", path]);
 ```

 But it only opens explorer.exe in the documents path and not 
 the path given.

 I've tried to set the working directory too and it doesn't 
 work either.

 Can anyone help me? All I want to do is open a specific 
 folder in explorer.exe given a specific path.
This may achieve what you want: `spawnProcess(["powershell", "invoke-item", "-path", path]);` Thanks, Jordan
Yeah I ended up doing something similar, but with cmd.
This have one downside, for example in real apps such as vscode going through right-click on folder and click "Show In Explorer" it will keep one instance of explorer, but with spawn process it doesn't tracks it and opens multiple explorer windows, so I use this snippet for windows. ```d version(Windows) { import core.sys.windows.windows; import core.sys.windows.shlobj; alias PCIDLIST_ABSOLUTE = ITEMIDLIST*; alias PIDLIST_ABSOLUTE = ITEMIDLIST*; alias PCUITEMID_CHILD_ARRAY = LPITEMIDLIST*; extern(Windows) HRESULT SHOpenFolderAndSelectItems(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl = null, DWORD dwFlags = 0); extern(Windows) PIDLIST_ABSOLUTE ILCreateFromPathW(PCTSTR pszPath); // implements "Open In Explorer" feature void browseToFile(string filename) { import std.utf; LPCTSTR _fpath = filename.toUTF16z; ITEMIDLIST *pidl = ILCreateFromPathW(_fpath); if (pidl) { SHOpenFolderAndSelectItems(pidl,0,null,0); ILFree(pidl); } } } ```
Dec 28 2024
prev sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
Not guaranteed to work on non-Windows (Posix does not unify this).

```d
void main(string[] args) {
         import std.process : browse;
         import std.path : dirName;
         browse(args[0].dirName);
}
```
Dec 28 2024