C#使用shell32獲取文件屬性的方法
更新時(shí)間:2015年04月24日 15:22:44 作者:令狐不聰
這篇文章主要介紹了C#使用shell32獲取文件屬性的方法,涉及C#通過shell32獲取文件屬性的相關(guān)技巧,需要的朋友可以參考下
本文實(shí)例講述了C#使用shell32獲取文件屬性的方法。分享給大家供大家參考。具體實(shí)現(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)無屬性可取時(shí),推出循環(huán)
break;
}
//獲取屬性值
string value = folder.GetDetailsOf(item, i);
//保存屬性
Properties.Add(key, value);
i++;
}
}
}
}
希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#使用分部類設(shè)計(jì)實(shí)現(xiàn)一個(gè)計(jì)算器
分部類是C#4.5中的一個(gè)新特性,它的出現(xiàn)使得程序的結(jié)構(gòu)更加合理,代碼組織更加緊密,本文將使用分部類設(shè)計(jì)實(shí)現(xiàn)一個(gè)簡單的計(jì)算器,感興趣的小伙伴可以了解下2024-02-02
WPF實(shí)現(xiàn)動(dòng)畫效果(七)之演示圖板
這篇文章介紹了WPF實(shí)現(xiàn)動(dòng)畫效果之演示圖板,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
C# CancellationToken和CancellationTokenSource的用法詳解
做了.net core之后,發(fā)現(xiàn)CancellationToken用的越來越平凡了。這也難怪,原來.net framework使用異步的不是很多,而.net core首推異步編程,到處可以看到Task的影子,而CancellationToken正好是異步Task的一個(gè)控制器,所以花點(diǎn)時(shí)間做個(gè)筆記2021-06-06

