Where does windows explorer store file meta data?
Asked Answered
M

4

14

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?

Metrical answered 21/5, 2011 at 7:35 Comment(3)
Could it be related to this?Albumenize
No, as I said, since it also works on FAT, no alternate data streams can be involved since FAT doesn't support themMetrical
On both FAT and NTFS, they could use extended attributes (en.wikipedia.org/wiki/Extended_file_attributes)Cenozoic
T
5

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.

Tichon answered 29/4, 2014 at 18:2 Comment(2)
-1 for " It really depends, and you really don't have to worry, nor should you worry." Understanding what happens under the hood helps debugging when someone else does something really stupid, then puts it on your desk.Lona
What if I'm wondering whether my tags will be available if I move to Linux? Should I invest time adding metadata via Windows' built-in properties system or find a 3rd party solution? It's pretty important to know where the data is stored if you're thinking about maintaining an archive.Nevadanevai
A
4

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

Amp answered 21/5, 2011 at 11:51 Comment(1)
Of course it only works for certain file types. For example, it's never going to work for a text file!Contractual
C
3

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

Charleycharlie answered 21/5, 2011 at 13:35 Comment(1)
COM Structured Storage is an older API. The properties presented in Explorer that the OP is asking about (title, rating -> think media files) can be accessed via IShellItem2 and IPropertyStore. This is different from COM Structured Storage.Tichon
R
1

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;
         }
   }
}
Restrictive answered 20/1, 2016 at 1:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.