Search code examples
windowswindows-explorerfile-browser

Open Windows Explorer from Javascript


I want to open a file directory on the windows explorer by clicking a button in my application.

Note: 1. I do not want a file browser/web viewer, but the Windows Explorer (Windows+E) 2. My application does not run on a web browser (e.g. Chrome, Explorer), but a batch file. So whether Chrome blocks local folder browsing is irrelevant to me!

Thanks.


Solution

  • Figured it out... Simply run shell script on your JS code! Node.js

    var exec = require('child_process').exec, child;
    
    var isWin = /^win/.test(process.platform); // possible outcomes -> 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
    
    exec((isWin?'start ':'open ') + name,
        function (error, stdout, stderr) {
            if (error !== null) {
                console.log('exec error: ' + error);
            }
        }
    );