Open directory in Node.js and node -webkit

I have a function that should open a directory after creating it,

setTimeout(function()
{
    var fs = require('fs');
    console.log(newPath);
    var open = fs.opensync(newPath, 'r');
}, 2500);

But this does not seem to work. I get the following errors

Firstly,

TypeError: undefined is not a function of eval (eval at <anonymous>(file: ///Users/proslav/Library/Developer/Xcode/DerivedData/trackingCore-ecxfviftqracjxhimcuhhhvyddso/Build/Products/Debug/trackingCore.app/Conttime/rents/ /Contents/Resources/app.nw/js/jquery-1.10.2.min.js: 3: 4994) ,: 43:18)

and second -

Untrained ReferenceError: require not defined

I thought it might be that my variable is newpathnot defined, but the log shows me the correct link. Creating a directory with var fs = require('fs');works fine.

What am I doing wrong here?

+4
2

, . Node -webkit . MAC . , , . nw.gui gui.Shell.showItemInFolder . .

/*---------
Open Folder
---------*/
function openFolder(path){
    var gui = require('nw.gui');
    gui.Shell.showItemInFolder(path);
}
+5

nw.js 0.13 :

nw.Shell.showItemInFolder(fullpath);

< 0,13:

var gui = require('nw.gui');
gui.Shell.showItemInFolder(fullpath);

, . , .

c:\foo\bar.txt, foo bar.txt. strong > .

c:\foo\foo2, foo foo2 ( foo2, ).


, node ( fs), node module (utils.js) :

exports.getFullPath = function(fileName) {
    var path = require('path');
    return path.resolve(__dirname, fileName);
}

:

function openFolder(path) {
    var utils = require('./utils');
    var fullpath = utils.getFullPath(path);
    nw.Shell.showItemInFolder(fullpath);
}
+1

All Articles