Today I tried to open the windows file explorer at a specific location using NWJS and allow the user to open any file. The software needs to keep running after the shortcut’s open.
The problem is all I find do not work as intended.
The shortcut path is in an string accessible by s.shortcut
I tried :
showOpenFilePicker(s.shortcut)
which opens the file picker, but don’t allow the user to open any file and can’t be opened at a specific location except default ones (documents, image, desktop, etc).window.open("file://" + s.shortcut)
which opens a web file explorer in the software itself, closing the program when closing the explorer and doesn’t allow to open file.window.open("file://" + s.shortcut, "explorer", "popup")
opens it in a web file explorer that doesn’t close the program when exited, but still doesn’t allow to open any file, only downloading them
I can’t find any other things that will work. Also, please note I’m using NWJS which has some access to the user’s computer.
Thank you in advance for any help or edit.
2
Answers
I found a way on node, if needed you can use the nodejs package
open-file-explorer
by doing :NW provides excellent file and directory pickers with no limits whatsoever, so why would you want to use the crippled showOpenFilePicker?
For access to the local file system use:
File picker with a specific location to start…
Open an image file picker…
Multi-file picker for uploading etc…
A "Save as.." dialog box for saving files…
A directory (folder) picker…
NB: You can alter the special attributes (nwsaveas/nwworkingdir) dynamically with…
Online documentation…
https://nwjs.readthedocs.io/en/latest/References/Changes%20to%20DOM/
Addressing your specific problem here’s how I load any viewable file from the disk, into an iframe…
AddNewTab() is my function that creates an iframe and sets the selected file path as the iframe’s source but the most important part is that we have to change the backward slashes to forward slashes.
So instead of this for the file path…
Use this…
I hope this helps.