[英]Retrieve and set file details using windows API?
I'm not able to programmatically get/set file details on Windows.我无法以编程方式获取/设置 Windows 上的文件详细信息。
I managed to get file size, creation time, last access, but those are information I don't actually need.我设法获得了文件大小、创建时间、上次访问权限,但这些是我实际上并不需要的信息。
I'd like to get/set information like "Author" or "Tag" or every other information you can see in the Details tab in the Properties window of a file, even custom ones (which may vary depending of the file itself).我想获取/设置诸如“作者”或“标签”之类的信息,或者您可以在文件的属性 window 的详细信息选项卡中看到的所有其他信息,甚至是自定义信息(可能因文件本身而异)。
These are properties
.这些是properties
。 Here is a how-to example: https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/Win7Samples/winui/shell/appplatform/PropertyEdit这是一个操作示例: https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/Win7Samples/winui/shell/appplatform/PropertyEdit
In case the link above will break, here are the core functions to use:如果上面的链接中断,这里是要使用的核心功能:
SHGetPropertyStoreFromParsingName SHGetPropertyStoreFromParsingName
This will return a IPropertyStore这将返回一个IPropertyStore
You can enumerate it by using IPropertyStore::GetCount and IPropertyStore::GetAt您可以使用IPropertyStore::GetCount和IPropertyStore::GetAt枚举它
Then, for each of the keys, you can IPropertyStore::GetValue and IPropertyStore::SetValue然后,对于每个键,您可以IPropertyStore::GetValue和IPropertyStore::SetValue
The properties you are referring to you are not a feature of the file system.您所指的属性不是文件系统的功能。 Rather they are metadata stored within specific known file formats.相反,它们是存储在特定已知文件格式中的元数据。
Windows is aware (through file format specific property handlers ) of specific formats such as Office documents and common media files, and can extract and present that information via the Windows Property System . Windows 了解(通过文件格式特定属性处理程序)Office 文档和常见媒体文件等特定格式,并可以通过Windows 属性系统提取和呈现该信息。
There a number of examples, including propertyedit
which is a command line tool that demonstrates how to set, get, enumerate and inspect the schema of any file that has a property handler associated with it.有许多示例,包括propertyedit
,它是一个命令行工具,它演示如何设置、获取、枚举和检查具有关联属性处理程序的任何文件的架构。
Perhaps of some interest also in the UWP API, that information can be accessed via various classes in the Windows.Storage.FileProperties
namespace.也许对 UWP API 也有一些兴趣,可以通过Windows.Storage.FileProperties
命名空间中的各种类访问该信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.