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

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;

猜你喜欢

转载自www.cnblogs.com/zxtceq/p/10121391.html