Vb.net 获取扩展文件信息详细信息
如何使用VB.net获取windows文件的详细信息 我指的是当我右键单击一个文件,比如说一个MS word文档,然后单击“属性”并选择“详细信息”选项卡时找到的详细信息类型 我知道有些可以通过FileInfo获得,但不是全部,比如“标签”。Vb.net 获取扩展文件信息详细信息,vb.net,windows,filesystems,Vb.net,Windows,Filesystems,如何使用VB.net获取windows文件的详细信息 我指的是当我右键单击一个文件,比如说一个MS word文档,然后单击“属性”并选择“详细信息”选项卡时找到的详细信息类型 我知道有些可以通过FileInfo获得,但不是全部,比如“标签”。 谢谢你使用Shell32所需要的东西。在COM选项卡中,查找并添加Microsoft Shell控件和自动化。下面是为给定文件创建属性值列表的代码: ”类来存放糖果 好友类ShellInfo 作为字符串的公共属性名称 作为字符串的公共属性值 Public
谢谢你使用Shell32所需要的东西。在COM选项卡中,查找并添加Microsoft Shell控件和自动化。下面是为给定文件创建属性值列表的代码:
”类来存放糖果
好友类ShellInfo
作为字符串的公共属性名称
作为字符串的公共属性值
Public Sub New(n作为字符串,v作为字符串)
Name=n
值=v
端接头
Public将函数ToString()重写为字符串
返回名称
端函数
末级
然后是一个函数来填充它
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、BitRate、Album
,关联的值将是Shell32
返回的值。e、 g
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控件和自动化重命名为Microsoft Shell文件夹视图路由器(在Windows 8.1中)
另外,前35个属性是相当知名和常见的,但Win7大约有291个。在Windows 8下,最大值为309,有一些空白点,列表中的某些属性索引已更改
有关您需要使用Shell32的内容,请参见回答相关问题。在COM选项卡中,查找并添加Microsoft Shell控件和自动化。下面是为给定文件创建属性值列表的代码:
”类来存放糖果
好友类ShellInfo
作为字符串的公共属性名称
作为字符串的公共属性值
Public Sub New(n作为字符串,v作为字符串)
Name=n
值=v
端接头
Public将函数ToString()重写为字符串
返回名称
端函数
末级
然后是一个函数来填充它
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、BitRate、Album
,关联的值将是Shell32
返回的值。e、 g
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控件和自动化重命名为Microsoft Shell文件夹视图路由器(在Windows 8.1中)
另外,前35个属性是相当知名和常见的,但Win7大约有291个。在Windows 8下,最大值为309,有一些空白点,列表中的某些属性索引已更改
查看此答案相关问题只需使用以下内容:
Dim MyFileInfos as System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(PathToYourFile)
然后使用MyFileInfo.
*(无论您需要什么,请使用IntelliSense)获取信息
祝你有愉快的一天只需使用以下方法:
Dim MyFileInfos as System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(PathToYourFile)
Dim shellAppType = Type.GetTypeFromProgID("Shell.Application")
Dim shellApp = Activator.CreateInstance(shellAppType)
Dim folder = shellApp.NameSpace("c:\users\frank")
Dim folderitem = folder.parsename("yourfile.jpg")
Dim value = folder.GetDetailsOf(folderitem, 24) 'eg. 24 retrieves File Comments.
然后使用MyFileInfo.
*(无论您需要什么,请使用IntelliSense)获取信息
祝您度过愉快的一天您可以使用Shell API,看看是否需要专门为word编写此API,您可以使用word.Interop来获取/设置此信息。@Steve,不,ta。需要它来处理各种文件类型。。。word、pdf、rtf、xml可能等等。您可以使用Shell API,看看是否需要专门用于word的API,您可以使用word.Interop来获取/设置此信息。@Steve,No,ta。各种文件类型都需要它。。。word、pdf、rtf、xml等都是非常好的工作代码。Microsoft Shell Controls and Automation更名为Microsoft Shell Folder View Router(在Windows 8.1中)@Kamlesh感谢您提供的信息-我将其添加到答案中以及Win 8中的一些其他更改。感谢您提供非常好的工作代码。Microsoft Shell Control and Automation更名为Microsoft Shell Folder View Router(在Windows 8.1中)@Kamlesh感谢您提供的信息-我将其添加到答案中,以及Win 8中的一些其他更改。
Dim shellAppType = Type.GetTypeFromProgID("Shell.Application")
Dim shellApp = Activator.CreateInstance(shellAppType)
Dim folder = shellApp.NameSpace("c:\users\frank")
Dim folderitem = folder.parsename("yourfile.jpg")
Dim value = folder.GetDetailsOf(folderitem, 24) 'eg. 24 retrieves File Comments.