简体   繁体   English

获取扩展文件属性

[英]Getting extended file properties

I found this post . 我找到了这个帖子

That explains how to get extended file properties in .net.这解释了如何在 .net 中获取扩展文件属性。 But it points to a Code Project article that is 10 years old.但它指向了一篇已有 10 年历史的 Code Project 文章。

The thread itself is 5 years old.线程本身已有 5 年历史。

Is there a better way now to get extended file properties like Title, SubTitle, Episode Name etc.?现在有没有更好的方法来获取扩展文件属性,如标题、副标题、剧集名称等?

What I would really like to do is to get the extended file information on individual files.我真正想做的是获取单个文件的扩展文件信息。 It looks to me like this code loops through a directory and gets the file info on those files.在我看来,这段代码循环遍历一个目录并获取这些文件的文件信息。

I used already the Windows API Code Pack我已经使用了Windows API 代码包

ShellObject picture = ShellObject.FromParsingName(file);

var camera = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraModel);
newItem.CameraModel = GetValue(camera, String.Empty, String.Empty);

var company = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraManufacturer);
newItem.CameraMaker = GetValue(company, String.Empty, String.Empty);

Link to a Blogpost by Rob Sanders - [Link removed.链接到Rob Sanders的博客文章 - [链接已删除。 It was pointing to malware.]它指向恶意软件。]

You can use my MetadataExtractor library to access all sorts of metadata from image and video files.您可以使用我的MetadataExtractor库从图像和视频文件中访问各种元数据。 It supports Exif, IPTC, and many other kinds of metadata.它支持 Exif、IPTC 和许多其他类型的元数据。

It's available on GitHub and NuGet .它在GitHubNuGet可用

In order to get this code to run you will need to add two nugget packages - I had to add older version from the package manager console as the latest version wouldn't install on my antediluvian VS 2012:为了让这段代码运行,你需要添加两个 nugget 包 - 我必须从包管理器控制台添加旧版本,因为最新版本不会安装在我的旧版 VS 2012 上:

    Install-Package WindowsAPICodePack-Core -Version 1.1.2
    Install-Package WindowsAPICodePack-Shell -Version 1.1.1

Below is some code to list all the properties:下面是一些列出所有属性的代码:

 using Microsoft.WindowsAPICodePack.Shell;

    private void ListExtendedProperties(string filePath)
    {
        var file = ShellObject.FromParsingName(filePath);
        var i = 0;
        foreach (var property in file.Properties.DefaultPropertyCollection)
        {
            var name = (property.CanonicalName ?? "unnamed-[" + i + "]").Replace("System.", string.Empty);
            var t = Nullable.GetUnderlyingType(property.ValueType) ?? property.ValueType;
            var value = (null == property.ValueAsObject)
                ? string.Empty
                : (Convert.ChangeType(property.ValueAsObject, t)).ToString();
            var friendlyName = property.Description.DisplayName;
            Console.WriteLine(i++ + " " + name + "/" + friendlyName + ": " + value);
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM