Node JS - 读取文件属性 [英] Node JS - read file properties
问题描述
我正在使用 NWJS 开发桌面应用程序,我需要获取 .exe 文件的文件属性.
I'm developing a Desktop Application with NWJS and I need to get the file properties of an .exe File.
我尝试使用 npm 属性模块 https://github.com/gagle/node-properties,但我得到一个空对象.
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:
我也尝试过使用 fs.stats,但没有成功.有什么想法吗?
I've also tried using fs.stats and no luck. Any ideas?
推荐答案
除非你想编写一些本地 C 模块,否则有一种很容易完成的hacky 方法:使用 windows wmic
命令.这是获取版本的命令(通过谷歌搜索找到):
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
所以你可以在 node 中运行这个命令来完成工作:
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
}
});
这篇关于Node JS - 读取文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!