node.jsnode-webkitfile-properties

Node JS - read file properties


I'm developing a Desktop Application with NWJS and I need to get the file properties of an .exe File.

I've tried using the npm properties module https://github.com/gagle/node-properties, but I get an empty Object.

properties.parse('./unzipped/File.exe', { path: true }, function (err, obj) {
            if (err) {
                console.log(err);
            }

            console.log(obj);
        });

I need to get the "File version" Property:

File Properties

I've also tried using fs.stats and no luck. Any ideas?


Solution

  • Unless you want to write some native C module, there is hacky way to get this done easily: using windows wmic command. This is the command to get version (found by googling):

    wmic datafile where name='c:\\windows\\system32\\notepad.exe' get Version
    

    so you can just run this command in node to get the job done:

    var exec = require('child_process').exec
    
    exec('wmic datafile where name="c:\\\\windows\\\\system32\\\\notepad.exe" get Version', function(err,stdout, stderr){
     if(!err){
       console.log(stdout)// parse this string for version
     }
    });