如何在Windows中使用golang获取文件描述(产品名称,原始filname等)?
发布时间:2020-05-22 12:21:39 所属栏目:Windows 来源:互联网
导读:golang中的Fileinfo给出Name,时间修改,大小等.我需要在 windows中使用golang获取特定文件的描述(例如:产品名称,原始filname等). 您可以使用Go的 w32 library for Win32 API调用.不需要CGo. 以下是如何通过GetFileVersionInfo和VerQueryValue检索所有文件信息
|
golang中的Fileinfo给出Name,时间修改,大小等.我需要在 windows中使用golang获取特定文件的描述(例如:产品名称,原始filname等). 您可以使用Go的 w32 library for Win32 API调用.不需要CGo. 以下是如何通过GetFileVersionInfo和VerQueryValue检索所有文件信息的示例: package main
import (
"fmt"
"github.com/gonutz/w32"
)
func main() {
const path = `C:some file`
size := w32.GetFileVersionInfoSize(path)
if size <= 0 {
panic("GetFileVersionInfoSize failed")
}
info := make([]byte,size)
ok := w32.GetFileVersionInfo(path,info)
if !ok {
panic("GetFileVersionInfo failed")
}
fixed,ok := w32.VerQueryValueRoot(info)
if !ok {
panic("VerQueryValueRoot failed")
}
version := fixed.FileVersion()
fmt.Printf(
"file version: %d.%d.%d.%dn",version&0xFFFF000000000000>>48,version&0x0000FFFF00000000>>32,version&0x00000000FFFF0000>>16,version&0x000000000000FFFF>>0,)
translations,ok := w32.VerQueryValueTranslations(info)
if !ok {
panic("VerQueryValueTranslations failed")
}
if len(translations) == 0 {
panic("no translation found")
}
fmt.Println("translations:",translations)
t := translations[0]
// w32.CompanyName simply translates to "CompanyName"
company,ok := w32.VerQueryValueString(info,t,w32.CompanyName)
if !ok {
panic("cannot get company name")
}
fmt.Println("company:",company)
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 在Windows上存储应用程序日志文件的位置
- 在Windows XP下安装Apache+MySQL+PHP环境
- 在Windows XP上安装后,Python无法看到加密模块
- 我在哪里报告Windows核心库问题?
- Win10远程桌面 出现 身份验证错误,要求的函数不
- Windows Server 2016-Active Directory复制概念(
- 如何在Window中的嵌入式浏览器中调试Javascript?
- windows-8 – 在MetroStyle应用程序中使用COM对象
- Windows Server 2012 R2智能卡限制
- Windows Server 2016-配置Windows Defender防病毒
热点阅读
