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();
//獲取文件所在父目錄對(duì)象
Folder folder = shell.NameSpace(filePath.Substring(0, filePath.LastIndexOf('//')));
//獲取文件對(duì)應(yīng)的FolderItem對(duì)象
FolderItem item = folder.ParseName(filePath.Substring(filePath.LastIndexOf('//')+1));
//字典存放屬性名和屬性值的鍵值關(guān)系對(duì)
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++;
}
}
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#獲取鼠標(biāo)在listview右鍵點(diǎn)擊單元格的內(nèi)容方法
下面小編就為大家?guī)硪黄狢#獲取鼠標(biāo)在listview右鍵點(diǎn)擊單元格的內(nèi)容方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-01-01
利用C#實(shí)現(xiàn)批量圖片格式轉(zhuǎn)換功能
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)批量圖片格式轉(zhuǎn)換功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-12-12
C#結(jié)合數(shù)據(jù)庫(kù)的數(shù)據(jù)采集器示例
這篇文章主要介紹了C#結(jié)合數(shù)據(jù)庫(kù)的數(shù)據(jù)采集器,功能比較實(shí)用,需要的朋友可以參考下2014-07-07
Ruby創(chuàng)建數(shù)組方法總結(jié)
在本篇文章里小編給大家分享了關(guān)于Ruby創(chuàng)建數(shù)組方法的知識(shí)點(diǎn)內(nèi)容,對(duì)戲有興趣的朋友們學(xué)習(xí)下。2019-01-01

