.net GetDetailsOf shell32.folderitem from string

时间:2013-06-24 00:59:29

标签: .net vb.net syntax file-attributes shell32.dll

我正在尝试使用vb.net中的GetDetailsOf来获取图像或视频文件的分辨率,但我不明白如何将文件加载到shell32.folderitem中,所以我这样做是非常迂回的。

    OpenFileDialog1.ShowDialog()
    Dim fi As New FileInfo(OpenFileDialog1.FileName)

    Dim shell As New Shell32.Shell
    Dim objFolder As Shell32.Folder

    objFolder = shell.NameSpace(fi.DirectoryName)
    For i As Integer = 0 To objFolder.Items.Count - 1
        If objFolder.Items(i).name = fi.Name Then

            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 31))
            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 282))
            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 280))
        End If
    Next

我只是循环浏览文件夹,直到找到与我的文件匹配的内容。有更清洁,更快的方法吗?我只需要从完整文件名中获得一个shell32.FolderItem。

另外,我可以依靠细节31来始终将分辨率和280/282作为帧高/帧宽吗?我怎么知道他们是否会在其他计算机上检索相同的细节而不必在其他计算机上进行测试?

感谢。

2 个答案:

答案 0 :(得分:1)

    Dim fi As New FileInfo(fileName)
    Dim shl As Shell32.Shell = New Shell32.Shell
    Dim dir As Shell32.Folder = shl.[NameSpace](fi.DirectoryName)
    Dim itm As Shell32.FolderItem = dir.Items().Item(fi.Name)
    Dim itm2 As Shell32.ShellFolderItem = DirectCast(itm, Shell32.ShellFolderItem)


    Dim str As String = dir.GetDetailsOf(itm2, 31)

这使它无需搜索文件即可运行。 31为我返回图像尺寸。 DirectoryInfo没有shell32“getdetailsof”具有的所有元数据。

答案 1 :(得分:0)

  

有更清洁,更快捷的方法吗?

这样的事情应该有效:

Imports System.IO

    Dim test() As FileSystemInfo = New DirectoryInfo("MyDirectoryPath").GetFileSystemInfos("MyImageFile")
    'MyImageFile is actually a search pattern string.  the result is an array 
    'containing info on every file in the folder that matches the search pattern.
    'If the pattern is unique then only one file will be returned and using
    'the FullName property will return the full path to the file.
    test(0).FullName()
    'Or just the Name property to return just the file name
    test(0).Name()