the option “Open file in folder” in the PhotoStructure desktop version on Windows (Win 10, in my case) is supposed to open the selected asset in the explorer. For some assets, it does not work for me – instead the explorer opens on some unrelated folder (Documents).
If I copy the selected and run
explorer /select,"Z:\Lars\Google Pixel 3\Camera\PXL_20210402_162401445.MP.jpg"
the explorer opens with the file selected, as expected.
Yup! Powershell escaping normally uses the backtick. I found yesterday via trial and error that if I want PowerShell to spawn explorer with a path with a single quote, I have to double up the single quote (sql-style!?!), and that backtick escaping was ignored.
I’ll verify the first double-quote placement is correct this morning.
No, thanks for that link! I built the current string escaping using a different microsoft reference.
I just checked the code:
async function explorerSelect(file: PosixFile): Promise<boolean> {
// The quotes around the paths make whitespace get handled correctly:
return run("explorer.exe", ['/select,"' + file.nativePath + '"'])
}
So… those quotes in the wrong place seem to have been “helpfully” added by Node. Forking via PowerShell should avoid those shenanigans.
Here’s the new implementation:
async function explorerSelect(file: PosixFile): Promise<boolean> {
const path = file.nativePath
// Double-quotes are not allowed in windows paths, but just to be safe:
.replace(/"/g, "")
// PowerShell supports escaping single quotes with two single quotes.
// See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules
.replace(/'/g, "''")
try {
await PowerShell.instance().execute(
`start explorer.exe -ArgumentList '/select,"${path}"'`,
SimpleParser
)
return true
} catch (err) {
logger().warn("explorerSelect(" + file + ") failed", err)
return false
}
}
@mrm I just realized this way allows to open the folder but cannot highlight the selected file, so your previous way is better. Sorry for the confusion