digitalmars.D.learn - Open a folder with explorer.exe
- bauss (12/12) Dec 28 2024 I cannot figure out how to get spawnProcess working with
- bauss (3/15) Dec 28 2024 Still haven't found a solution. Ended up calling cmd.exe and
- Jordan Wilson (5/17) Dec 28 2024 This may achieve what you want:
- bauss (3/25) Dec 28 2024 Yeah I ended up doing something similar, but with cmd.
- evilrat (30/58) Dec 28 2024 This have one downside, for example in real apps such as vscode
- Richard (Rikki) Andrew Cattermole (8/8) Dec 28 2024 Not guaranteed to work on non-Windows (Posix does not unify this).
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
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
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
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:Yeah I ended up doing something similar, but with cmd.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
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: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); } } } ```On Saturday, 28 December 2024 at 18:55:08 UTC, bauss wrote:Yeah I ended up doing something similar, but with cmd.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
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