Windows 资源管理器在哪里存储文件元数据?

发布于 2024-11-08 19:40:11 字数 125 浏览 4 评论 0原文

在 Windows 7 中,我可以向文件添加元数据,例如标题、评级等。这些元数据到底存储在哪里?对于 NTFS,他们可能使用备用数据流,但我这个元数据也恰好在 FAT32 中工作,那么他们是如何做到的呢?是否有 API 可以使用此功能?

In Windows 7 I can add meta data to files for example title, rating and so on. Where is this meta data stored exactly? For NTFS they may use alternate data streams but I this meta data also happen to work in FAT32, so how ho they do it? Is there an API to make use of this feature?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

紧拥背影 2024-11-15 19:40:11

在 Windows 7 中,我可以[使用资源管理器]向文件添加元数据,例如标题、评级等。这些元数据到底存储在哪里?

此元数据称为“属性”。从 Windows Vista 开始就以这种方式提供。

Windows 资源管理器以统一的方式显示属性,这可能会让您误以为它们都来自同一家商店。但事实并非如此。

属性通过 API 暴露给程序员。 (见下文。)

它们的确切存储位置是实现细节。这取决于文件类型和属性类型。例如,文件系统时间戳作为属性公开。媒体文件元数据(例如图像的 EXIF 或 MP3 的 ID3 标签)存储在文件本身中。还有其他元数据可能存储在与您正在检查其属性的文件一起的 XML 文件中。

那么它存储在哪里呢?答案是:这确实要看情况,你真的不必担心,也不应该担心。因为,正如我所说,这是一个实现细节,就编程而言,担心实现细节意味着绕过 API。

在 API 级别处理属性时,您也不必担心属性存储在哪里。请参阅 IShellItem2< /code>IPropertyStore 入口点的 COM 接口。

在底层,Windows Vista 和更高版本提供了了解文件类型以及如何读写其属性的属性处理程序。您可以编写自己的属性处理程序(使用 COM)并将其添加到资源管理器(作为所谓的 shell 扩展)。

我发现的最有用的文档是 Ben Karas 在 2006 年 8 月开始发布 Vista 前后的博客文章。他完成了关于财产系统的整个系列。这是一个非常有用的教程,对于我使用 Windows 7 来说,它的效果 100%。

不要按照本页另一条回复中给出的建议来阅读COM 结构化存储。这仅适用于特定文件类型。 Ben Karas 的话 :

问题:很多人错误地调用了StgOpenStorageEx。不要那样做! StgOpenStorageEx 支持特定格式,例如 OLE 复合文档或 NTFS 辅助流存储。 StgOpenStorageEx 不知道如何从 .JPG 图像中读取 EXIF 标头。

In Windows 7 I can add meta data to files [using Explorer] for example title, rating and so on. Where is this meta data stored exactly?

This metadata is called properties. It has been available in this way since Windows Vista.

Windows Explorer presents properties in a unified way, which might trick you into thinking that they're all coming from the same shop. But this is not the case.

Properties are exposed to the programmer via an API. (See below.)

Where exactly they're stored is an implementation detail. It depends on the filetype and on the kind of property. For example, filesystem timestamps are exposed as properties. Media file metadata such as EXIF for images or ID3 tags for MP3 is stored in the file itself. Still other metadata might be stored in an XML file accompanying the file whose properties you're inspecting.

So where is it stored? The answer is: It really depends, and you really don't have to worry, nor should you worry. Because, as I said, it is an implementation detail, and as far as programming goes, worrying about implementation details means bypassing the API.

Neither do you have to worry where properties are stored when dealing with them at the API level. See the IShellItem2 and IPropertyStore COM interfaces for an entry point.

Under the hood, Windows Vista and later versions ship property handlers that know about filetypes and how to read and write their properties. You could write a property handler of your own (using COM) and add it to Explorer (as a so-called shell extension).

The most useful documentation which I've found is Ben Karas' blog entries around the time of the Vista release starting in August 2006. He's done a whole series on the property system. It's a very useful tutorial, and for me using Windows 7, it has worked 100 %.

Don't follow the advice given in another reply on this page to read up about COM Structured Storage. This is only for specific filetypes. In the words of Ben Karas:

Gotcha: Many people mistakenly call StgOpenStorageEx. Don't do that! StgOpenStorageEx is only supported for specific formats like OLE Compound Documents or NTFS secondary stream storage. StgOpenStorageEx doesn't know how to read the EXIF header from a .JPG image.

入怼 2024-11-15 19:40:11

从 Windows Vista 开始,元数据现在存储在文件本身内。

Starting with Windows Vista, metadata is now stored inside the file itself.

却一份温柔 2024-11-15 19:40:11

Windows 将其存储在 COM 结构化存储中。实现可以在文件本身中(Office 文档支持此功能,或任何支持结构化存储的文件格式),也可以在 NTFS 本身中。

该 API 位于此处:结构化存储。有趣的函数是 StgOpenStorageEx

以下是有关 NTFS 实施的一些详细信息: IPropertySetStorage-NTFS文件系统实现

Windows stores this in COM Structured storage. The implementation is either in the file itself (Office docs support this, or any file format that supports structured storage), or in NTFS itself.

The API is available here: Structured Storage. The interesting function is StgOpenStorageEx.

Here are some details about NTFS implementation: IPropertySetStorage-NTFS File System Implementation

晚雾 2024-11-15 19:40:11

由于您询问的是 .Net,因此您可以使用 Microsoft.WindowsAPICodePack- 访问文件属性来自 nuget 的 Shell 库。它提供了 的 .Net 接口Windows 属性

该库的使用示例如下:

using System;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using Microsoft.WindowsAPICodePack.Shell;

namespace Properties
{
    public class PictureFileProperties
    {
        public string GetCamera(string filename)
        {
            if (!System.IO.File.Exists(filename))
                return null;

            ShellObject picture = ShellObject.FromParsingName(filename);
            if (picture != null)
            {
                var manufacturer = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraManufacturer)).Value;
                var model = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraModel).Value;
                return string.Format("{0} {1}", manufacturer, model);
            }

            return null;
         }
   }
}

Since you're asking about .Net, you can access file properties using the Microsoft.WindowsAPICodePack-Shell library from nuget. It provides a .Net interface to Windows Properties.

An example use of the library is as follows:

using System;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using Microsoft.WindowsAPICodePack.Shell;

namespace Properties
{
    public class PictureFileProperties
    {
        public string GetCamera(string filename)
        {
            if (!System.IO.File.Exists(filename))
                return null;

            ShellObject picture = ShellObject.FromParsingName(filename);
            if (picture != null)
            {
                var manufacturer = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraManufacturer)).Value;
                var model = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraModel).Value;
                return string.Format("{0} {1}", manufacturer, model);
            }

            return null;
         }
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文