C#使用shell32獲取文件屬性的方法
更新時間:2015年04月24日 15:22:44 作者:令狐不聰
這篇文章主要介紹了C#使用shell32獲取文件屬性的方法,涉及C#通過shell32獲取文件屬性的相關(guān)技巧,需要的朋友可以參考下
本文實例講述了C#使用shell32獲取文件屬性的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Shell32; namespace GetFileCreator { class Program { static void Main(string[] args) { //要獲取屬性的文件路徑 string filePath = @"e:/f/aa.txt"; //初始化Shell接口 Shell32.Shell shell = new Shell32.ShellClass(); //獲取文件所在父目錄對象 Folder folder = shell.NameSpace(filePath.Substring(0, filePath.LastIndexOf('//'))); //獲取文件對應(yīng)的FolderItem對象 FolderItem item = folder.ParseName(filePath.Substring(filePath.LastIndexOf('//')+1)); //字典存放屬性名和屬性值的鍵值關(guān)系對 Dictionary<string, string> Properties = new Dictionary<string, string>(); int i =0; while (true) { //獲取屬性名稱 string key = folder.GetDetailsOf(null, i); if (string.IsNullOrEmpty(key)) { //當(dāng)無屬性可取時,推出循環(huán) break; } //獲取屬性值 string value = folder.GetDetailsOf(item, i); //保存屬性 Properties.Add(key, value); i++; } } } }
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C# CancellationToken和CancellationTokenSource的用法詳解
做了.net core之后,發(fā)現(xiàn)CancellationToken用的越來越平凡了。這也難怪,原來.net framework使用異步的不是很多,而.net core首推異步編程,到處可以看到Task的影子,而CancellationToken正好是異步Task的一個控制器,所以花點時間做個筆記2021-06-06