Node JS - 读取文件属性

Gab*_*ich 5 file-properties node.js node-webkit

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

我已经尝试使用npm属性模块https://github.com/gagle/node-properties,但我得到一个空的Object.

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

            console.log(obj);
        });
Run Code Online (Sandbox Code Playgroud)

我需要获取"文件版本"属性:

文件属性

我也试过使用fs.stats而没有运气.有任何想法吗?

has*_*sin 3

除非您想编写一些本机 C 模块,否则有一种简单的方法可以轻松完成此操作:使用 windowswmic命令。这是获取版本的命令(通过谷歌搜索找到):

wmic datafile where name='c:\\windows\\system32\\notepad.exe' get Version
Run Code Online (Sandbox Code Playgroud)

因此,您只需在节点中运行此命令即可完成工作:

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
 }
});
Run Code Online (Sandbox Code Playgroud)

  • $ wmic 数据文件,其中 name="C:\Development\nwjs\sistelupdater\unzipped\StaClient.exe" 获取版本节点 - USUARIO-PC 错误:描述 = 无效查询 (2认同)