Fileinfo in golang gives Name, time modified, size, etc. I need to get particular File's description(eg: Product name, Original filname, etc.) using golang in windows.
1条回答 默认 最新
- doupian9798 2017-09-14 14:43关注
You can use the w32 library for Win32 API calls from Go. No CGo needed.
Here is an example of how you can retrieve all file information through GetFileVersionInfo and 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.%d ", 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) }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 防火墙的混合模式配置
- ¥15 Ubuntu不小心注销了要怎么恢复啊
- ¥15 win10电脑安装完plcsim advanced4.0运行时为什么会提示找不到虚拟网卡
- ¥15 安装powerbuilder10卡在安装程序正在运行这个页面 没有下一步任何指令
- ¥15 关于mpi的问题:请问遇到这种情况需要怎么解决,出现这个问题后电脑不能进行mpi多核运行只能进行单核运行
- ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
- ¥15 python怎么在已有视频文件后添加新帧
- ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
- ¥15 fluent里模拟降膜反应的UDF编写
- ¥15 MYSQL 多表拼接link