C#使用shell32获取文件属性的方法
2015-04-24 15:22
951 查看
本文实例讲述了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#程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- [c#美味]使用Http Head方法获取文件长度
- 使用ShellClass获取文件属性详细信息的实现方法
- 文件属性获取及控件ListView使用常用方法
- C# 获取资源文件中的DLL,调用DLL中的方法
- C#使用StackTrace获取方法被谁调用
- C#使用iCSharpcode进行文件压缩实现方法
- C#获取程序文件相关信息的方法
- 如何使用libcurl实现HTTP的GET方法获取文件长度
- 使用JAVA读写Properties属性文件的方法详解
- SharedPreferences具体使用方法及createPackageContext方法(获取其他应用的共享文件)
- 使用Microsoft Symbol Server获取调试符号文件和DUMP文件具体分析方法
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- 使用JAVA读写Properties属性文件的方法详解
- C#中网页文件下载——HttpWebRequest与HttpWebResponse的使用方法
- C# static方法-使用迭代器循环遍历文件中的额行
- Java 使用反射获取类、方法、属性上的注释
- 修改system.img的文件的权限和属性:使用make.ext4fs的方法
- Windows批处理中获取文件属性的一些方法
- C# 使用资源文件 Resource.resx 的方法
- asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)