获取扩展的文件信息

如何使用VB.net获取windows文件的详细信息?

我所指的细节types是在右键单击文件时发现的,例如MS Word文档,然后单击“属性”并select“详细信息”选项卡。

我知道一些可以通过FileInfo获得,但不是全部,例如“标签”。 谢谢

Solutions Collecting From Web of "获取扩展的文件信息"

对于那些东西你需要使用Shell32。 从COM选项卡中查找并添加Microsoft Shell控件和自动化 。 以下是为给定文件创建属性值列表的代码:

' class to hold the goodies Friend Class ShellInfo Public Property Name As String Public Property Value As String Public Sub New(n As String, v As String) Name = n Value = v End Sub Public Overrides Function ToString() As String Return Name End Function End Class 

然后一个函数来填补它

 Private Function GetXtdShellInfo(filepath As String) As List(Of ShellInfo) ' ToDo: add error checking, maybe Try/Catch and ' surely check if the file exists before trying Dim xtd As New List(Of ShellInfo) Dim shell As New Shell32.Shell Dim shFolder As Shell32.Folder shFolder = shell.NameSpace(Path.GetDirectoryName(filepath)) ' its com so iterate to find what we want - ' or modify to return a dictionary of lists for all the items Dim key As String For Each s In shFolder.Items ' look for the one we are after If shfolder.GetDetailsOf(s, 0).ToLowerInvariant = Path.GetFileName(file).ToLowerInvariant Then Dim ndx As Int32 = 0 key = shfolder.GetDetailsOf(shfolder.Items, ndx) ' there are a varying number of entries depending on the OS ' 34 min, W7=290, W8=309 with some blanks ' this should get up to 310 non blank elements Do Until String.IsNullOrEmpty(key) AndAlso ndx > 310 If String.IsNullOrEmpty(key) = False Then xtd.Add(New ShellInfo(key, shfolder.GetDetailsOf(s, ndx))) End If ndx += 1 key = shfolder.GetDetailsOf(shfolder.Items, ndx) Loop ' we got what we came for Exit For End If Next Return xtd End Function 

使用它很简单:

 Dim xtd As List(Of ShellInfo) = GetXtdShellInfo("C:\Temp\Capri.jpg") For Each s As ShellInfo In xtd Console.WriteLine("{0}: {1}", s.Name, s.Value) Next 

返回值应该是一个ShellInfo项目列表,其中Name是属性名称,如Name, BitRate, Album ,并且关联的Value将是Shell32返回的Shell32 。 例如

  Name: Capri.jpg Size: 15.2 KB Item type: Image File Date modified: 7/20/2014 12:19 PM Date created: 7/20/2014 12:17 PM Date accessed: 7/20/2014 12:17 PM (etc) 

返回的实际数量会因操作系统版本而异


正如注释中所述, Microsoft Shell Controls and Automation被重命名为Microsoft Shell Folder View Router (在Windows 8.1中)。

此外,前35个属性是相当知名的和更常见的,但与Win7有大约291.在Windows 8下,最大是309有一些空白点,深入名单一些房地产指数改变。

如何从.mov视频文件头中读取比特率信息