C#通過shell32獲取文件屬性

pb44 9年前發布 | 3K 次閱讀 C#

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('//'))); //獲取文件對應的FolderItem對象 FolderItem item = folder.ParseName(filePath.Substring(filePath.LastIndexOf('//')+1)); //字典存放屬性名和屬性值的鍵值關系對 Dictionary<string, string> Properties = new Dictionary<string, string>(); int i =0; while (true) { //獲取屬性名稱 string key = folder.GetDetailsOf(null, i); if (string.IsNullOrEmpty(key)) { //當無屬性可取時,推出循環 break; } //獲取屬性值 string value = folder.GetDetailsOf(item, i); //保存屬性 Properties.Add(key, value); i++; } } } } </pre>

 本文由用戶 pb44 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!