Thread overview
Open a folder with explorer.exe
Dec 28
bauss
Dec 28
bauss
Dec 28
bauss
Dec 29
evilrat
December 28

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.

December 28

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.

December 28

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

December 28

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.

December 29
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);
}
```
December 29

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.

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