C#通过shell32获取文件详细备注信息

来源:互联网 发布:阿里云cdn配置https 编辑:程序博客网 时间:2024/06/16 22:43

1.从系统Window/System32文件夹中Copy出 Shell32.dll Com组件

将Shell32.dll文件引用到项目中,并设置“嵌入互操作类型”为false

http://blog.csdn.net/u011127019/article/details/52166033

2.代码实例:

ShellClass sh = new ShellClass();Folder dir = sh.NameSpace(Path.GetDirectoryName(filename));FolderItem item = dir.ParseName(Path.GetFileName(filename));StringBuilder sb = new StringBuilder();for (int i = -1; i < 50; i++){    // 0 Retrieves the name of the item.     // 1 Retrieves the size of the item.     // 2 Retrieves the type of the item.     // 3 Retrieves the date and time that the item was last modified.     // 4 Retrieves the attributes of the item.     // -1 Retrieves the info tip information for the item.     sb.Append(i.ToString());    sb.Append(":");    sb.Append(dir.GetDetailsOf(item, i));    sb.Append("/r/n");}string c = sb.ToString();
索引说明(视频文件常用属性):

0--文件名称

1---文件大小
2---文件类型
3---修改时间
4---创建时间
8---可用性
27---时长

28--比特率

303--数据速率

304--帧高度

305--帧速率

306--帧宽度

307--视频方向

308--总比特率

3.代码实例(有不可取的地方):

//初始化Shell接口ShellClass sh = new ShellClass();//获取文件所在父目录对象Folder dir = sh.NameSpace(Path.GetDirectoryName(filename));//获取文件对象的FolderItem对象FolderItem item = dir.ParseName(Path.GetFileName(filename));//字典存放属性名和属性值Dictionary<string, string> dic = new Dictionary<string, string>();//循环获取详细信息int i = 0;while (true){    //获取属性名称    string key = dir.GetDetailsOf(null,i);    if (string.IsNullOrEmpty(key))    {        //当无属性可取时,退出循环        break;    }    //获取属性值    string value = dir.GetDetailsOf(item,i);    dic.Add(key,value);    i++;}listBox.ItemsSource = dic;

更多:

ffmpeg ffplay ffprobe资料整理

C#使FFmpeg 将视频格式转换成MP4示例

1 0
原创粉丝点击