如何从文件路径获取应用程序名称/元数据 [英] How to get app name / metadata from file path

查看:21
本文介绍了如何从文件路径获取应用程序名称/元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有应用程序/可执行文件路径,我想从它们中获取友好的应用程序名称。假设一个getAppName函数如下:

const result = getAppName('C:\Program Files\Mozilla Firefox\firefox.exe');
console.log(result); // Firefox

例如,在Windows上,如果您右键单击应用程序并单击"属性",您可以在常规>描述和详细信息>文件描述中看到此名称;

我找不到NPM包、系统命令等。最后,我需要一个针对Linux、Mac和Windows的解决方案。理想情况下,有一种方法可以通过内置的Node.js包或NPM上的其他东西来实现,但我可能必须使用从Node.js执行的三个特定于操作系统的系统命令来拼凑出一个解决方案。

我找到了WMIC(在How to check file properties through WMI command line中)for Windows,但我无法从中得到我想要的;

wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get Description

Description
C:Program FilesMozilla Firefoxfirefox.exe
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get Name

Name
C:Program FilesMozilla Firefoxfirefox.exe
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get File Description

Invalid GET Expression.
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get File Name

Invalid GET Expression.
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get FileName

FileName
firefox
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get FileDescription

Node - XPS
ERROR:
Description = Invalid query
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get ProductName

Node - XPS
ERROR:
Description = Invalid query
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe"

AccessMask  Archive  Caption                                       Compressed  CompressionMethod  CreationClassName  CreationDate               CSCreationClassName   CSName  Description                                   Drive  EightDotThreeFileName                         Encrypted  EncryptionMethod  Extension  FileName  FileSize  FileType     FSCreationClassName  FSName  Hidden  InstallDate                InUseCount  LastAccessed               LastModified               Manufacturer         Name                                          Path                             Readable  Status  System  Version      Writeable
1179817     TRUE     C:Program FilesMozilla Firefoxfirefox.exe  FALSE                          CIM_LogicalFile    20190906213704.287820+060  Win32_ComputerSystem  XPS     C:Program FilesMozilla Firefoxfirefox.exe  c:     c:program filesmozilla firefoxfirefox.exe  FALSE                        exe        firefox   576032    Application  Win32_FileSystem     NTFS    FALSE   20190906213704.287820+060              20190907195815.492271+060  20190906213710.011611+060  Mozilla Corporation  C:Program FilesMozilla Firefoxfirefox.exe  program filesmozilla firefox  TRUE      OK      FALSE   69.0.0.7178  TRUE
C:Usersadaml>wmic datafile where name="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" get "file system name"

FSName
NTFS
C:Usersadaml>wmic datafile where name="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" get "file system class name"

FSCreationClassName
Win32_FileSystem

我不想做任何事情,比如采用无扩展名的文件名并将第一个字符大写。我想要显示给用户的准确/真实姓名。

推荐答案

我不确定这是否涵盖了所有内容,但这是我到目前为止得到的最好的。exiftool-vendored包允许您获得ProductName"标记",这就是我要找的;

const exiftool = require('exiftool-vendored').exiftool;

exiftool
  .read('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
  .then(tags =>
    console.log(tags.ProductName))
  .catch(err => console.error('Something terrible happened: ', err));

这篇关于如何从文件路径获取应用程序名称/元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆