节点JS – 读取文件属性

我正在开发一个NWJS的桌面应用程序,我需要获取.exe文件的文件属性。

我试过使用npm属性模块https://github.com/gagle/node-properties ,但我得到一个空的对象。

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

我需要得到“文件版本”属性:

文件属性

我也尝试使用fs.stats,没有运气。 有任何想法吗?

除非你想编写一些本地的C模块,否则很容易做到这一点:使用windows wmic命令。 这是获取版本的命令(通过Googlesearch):

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

所以你可以在node中运行这个命令来完成这个工作:

 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 } });