[C#] C#通过shell32获取文件属性 →→→→→进入此内容的聊天室

来自 , 2020-12-19, 写在 C#, 查看 143 次.
URL http://www.code666.cn/view/5c3b99e8
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using Shell32;  
  6.    
  7. namespace GetFileCreator  
  8. {  
  9.     class Program  
  10.     {  
  11.         static void Main(string[] args)  
  12.         {  
  13.             //要获取属性的文件路径  
  14.             string filePath = @"e:/f/aa.txt";  
  15.             //初始化Shell接口  
  16.             Shell32.Shell shell = new Shell32.ShellClass();  
  17.             //获取文件所在父目录对象  
  18.             Folder folder = shell.NameSpace(filePath.Substring(0, filePath.LastIndexOf('//')));  
  19.             //获取文件对应的FolderItem对象  
  20.             FolderItem item = folder.ParseName(filePath.Substring(filePath.LastIndexOf('//')+1));  
  21.             //字典存放属性名和属性值的键值关系对  
  22.             Dictionary<string, string> Properties = new Dictionary<string, string>();  
  23.             int i =0;  
  24.             while (true)  
  25.             {  
  26.                 //获取属性名称  
  27.                 string key = folder.GetDetailsOf(null, i);  
  28.                 if (string.IsNullOrEmpty(key))  
  29.                 {  
  30.                     //当无属性可取时,推出循环  
  31.                     break;  
  32.                 }  
  33.                 //获取属性值  
  34.                 string value = folder.GetDetailsOf(item, i);  
  35.                 //保存属性  
  36.                 Properties.Add(key, value);  
  37.                 i++;  
  38.             }  
  39.         }  
  40.     }  
  41. }  
  42. //csharp/6830

回复 "C#通过shell32获取文件属性"

这儿你可以回复上面这条便签

captcha