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;