gpt4 book ai didi

node.js - 如何从文件路径获取应用程序名称/元数据

转载 作者:太空宇宙 更新时间:2023-11-04 05:46:21 25 4
gpt4 key购买 nike

我有应用程序/可执行文件路径,我想从中获取友好的应用程序名称。想象一下这样的 getAppName 函数:

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

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

The "General" tab of Google Chrome's Properties

The "Details" tab of Google Chrome's Properties

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

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

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

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

Name
C:\Program Files\Mozilla Firefox\firefox.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 Files\Mozilla Firefox\firefox.exe FALSE CIM_LogicalFile 20190906213704.287820+060 Win32_ComputerSystem XPS C:\Program Files\Mozilla Firefox\firefox.exe c: c:\program files\mozilla firefox\firefox.exe FALSE exe firefox 576032 Application Win32_FileSystem NTFS FALSE 20190906213704.287820+060 20190907195815.492271+060 20190906213710.011611+060 Mozilla Corporation C:\Program Files\Mozilla Firefox\firefox.exe \program files\mozilla firefox\ TRUE OK FALSE 69.0.0.7178 TRUE
C:\Users\adaml>wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get "file system name"

FSName
NTFS
C:\Users\adaml>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));

关于node.js - 如何从文件路径获取应用程序名称/元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57836919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com