读/写“扩展"文件属性 (C#) [英] Read/Write 'Extended' file properties (C#)

查看:46
本文介绍了读/写“扩展"文件属性 (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出如何在 C# 中读取/写入扩展文件属性例如您可以在 Windows 资源管理器中看到的评论、比特率、访问日期、类别等.任何想法如何做到这一点?我将主要读取/写入视频文件(AVI/DIVX/...)

I'm trying to find out how to read/write to the extended file properties in C# e.g. Comment, Bit Rate, Date Accessed, Category etc that you can see in Windows explorer. Any ideas how to do this? I'll mainly be reading/writing to video files (AVI/DIVX/...)

推荐答案

对于那些不喜欢 VB 的人,这里是 C#:

For those of not crazy about VB, here it is in c#:

注意,您必须从引用"对话框的COM"选项卡中添加对 Microsoft Shell 控件和自动化的引用.

Note, you have to add a reference to Microsoft Shell Controls and Automation from the COM tab of the References dialog.

public static void Main(string[] args)
{
    List<string> arrHeaders = new List<string>();

    Shell32.Shell shell = new Shell32.Shell();
    Shell32.Folder objFolder;

    objFolder = shell.NameSpace(@"C:	emp	estprop");

    for( int i = 0; i < short.MaxValue; i++ )
    {
        string header = objFolder.GetDetailsOf(null, i);
        if (String.IsNullOrEmpty(header))
            break;
        arrHeaders.Add(header);
    }

    foreach(Shell32.FolderItem2 item in objFolder.Items())
    {
        for (int i = 0; i < arrHeaders.Count; i++)
        {
            Console.WriteLine(
              $"{i}	{arrHeaders[i]}: {objFolder.GetDetailsOf(item, i)}");
        }
    }
}

这篇关于读/写“扩展"文件属性 (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆