javascriptfilenwjs

How to open the windows file explorer on NWJS?


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 :

  1. 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).
  2. 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.
  3. 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.


Solution

  • I found a way on node, if needed you can use the nodejs package open-file-explorer by doing :

    const openExplorer = require('open-file-explorer');
    openExplorer(s.shortcut, err => {
        if(err) {
            console.log(err);
        }
        else {
            //Do Something
        }
    });