C#應用shell32獲得文件屬性的辦法。本站提示廣大學習愛好者:(C#應用shell32獲得文件屬性的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#應用shell32獲得文件屬性的辦法正文
本文實例講述了C#應用shell32獲得文件屬性的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
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++;
}
}
}
}
願望本文所述對年夜家的C#法式設計有所贊助。