您的位置:首页 > 移动开发 > Objective-C

如何获取文件的摘要信息!!!!

2006-08-14 16:27 471 查看
因是vb.net业余编程者,想获取一文件的摘要信息,百思不得其解,在网上狂搜,终于查出该资料:可网上均是C#的代码:可参见:Knight94(愚翁)的博客http://blog.csdn.net/knight94/archive/2006/05/11/724967.aspxhttp://www.codeproject.com/cs/files/detailedfileinfo.asp

故将其转换成vb.net的代码,以供像我一样的菜鸟查阅:

前提条件:需引用COM:Microsoft Shell Controls and Automation" (shell32.dll)

代码如下:

mports Shell32
Imports System.IO
Imports System.Text
Imports System

Public Class CFileInfo
    '
    ' Returns the detailed Information of a given file.
    '</summary>
    Private sFileName As String = ""
    Private sFullFileName As String = ""
    Private sFileExtension As String = ""
    Private sFilePath As String = ""
    Private sFileComment As String = ""
    Private sFileAuthor As String = ""
    Private sFileTitle As String = ""
    Private sFileSubject As String = ""
    Private sFileCategory As String = ""
    Private sFileType As String = ""
    Private lFileLength As Long = 0
    Private lFileVersion As Long = 0
    Private dCreationDate, dModificationDate As DateTime
    Public Sub New(ByVal sFPath As String)
        'check if the given File exists
        If (File.Exists(sFPath)) Then
            Dim aDetailedInfo As ArrayList = New ArrayList()
            Dim oFInfo As FileInfo = New FileInfo(sFPath)

            sFileName = oFInfo.Name

            sFullFileName = oFInfo.FullName

            sFileExtension = oFInfo.Extension

            lFileLength = oFInfo.Length

            sFilePath = oFInfo.Directory.ToString()

            dCreationDate = oFInfo.CreationTime

            dModificationDate = oFInfo.LastWriteTime

            ' #Region "read File Details"

            aDetailedInfo = GetDetailedFileInfo(sFPath)
            For Each oDFI As DetailedFileInfo In aDetailedInfo
                Select Case oDFI.ID
                    Case 2
                        sFileType = oDFI.Value
                        'Exit For
                    Case 9
                        sFileAuthor = oDFI.Value
                        'Exit For
                    Case 10
                        sFileTitle = oDFI.Value
                        ' Exit For
                    Case 11
                        sFileSubject = oDFI.Value
                        ' Exit For
                    Case 12
                        sFileCategory = oDFI.Value
                        ' Exit For
                    Case 14
                        sFileComment = oDFI.Value
                        ' Exit For
                    Case Else
                        ' Exit For
                End Select
                MessageBox.Show(oDFI.ID & "____" & oDFI.Value)
            Next
            '  #End Region
        Else
            Throw New Exception("The given File does not exist")
        End If
    End Sub
#Region "Properties"
    Public Property FileName() As String
        Get
            Return sFileName
        End Get
        Set(ByVal value As String)
            sFileName = value
        End Set
    End Property

    Public Property FilePath() As String
        Get
            Return sFilePath
        End Get
        Set(ByVal value As String)
            sFilePath = value
        End Set
    End Property

    Public Property FullFileName() As String
        Get
            Return sFullFileName
        End Get
        Set(ByVal value As String)
            sFullFileName = value
        End Set
    End Property

    Public Property FileExtension() As String
        Get
            Return sFileExtension
        End Get
        Set(ByVal value As String)
            sFileExtension = value
        End Set
    End Property

    Public Property FileSize() As Long
        Get
            Return lFileLength
        End Get
        Set(ByVal value As Long)
            lFileLength = value
        End Set
    End Property

    Public Property FileVersion() As Long
        Get
            Return lFileVersion
        End Get
        Set(ByVal value As Long)
            lFileVersion = value
        End Set
    End Property

    Public Property FileCreationDate() As DateTime
        Get
            Return dCreationDate
        End Get
        Set(ByVal value As DateTime)
            dCreationDate = value
        End Set
    End Property
    Public Property FileModificationDate() As DateTime
        Get
            Return dModificationDate
        End Get
        Set(ByVal value As DateTime)
            dModificationDate = value
        End Set
    End Property

    Public ReadOnly Property FileType() As String
        Get
            Return sFileType
        End Get
    End Property

    Public ReadOnly Property FileTitle() As String
        Get
            Return sFileTitle
        End Get
    End Property
    Public ReadOnly Property FileSubject() As String
        Get
            Return sFileSubject
        End Get
    End Property

    Public Property FileAuthor() As String
        Get
            Return sFileAuthor
        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property FileCategory() As String
        Get
            Return sFileCategory
        End Get<
bf16
br />        Set(ByVal value As String)

        End Set
    End Property

    Public Property FileComment() As String
        Get
            Return sFileComment
        End Get
        Set(ByVal value As String)

        End Set
    End Property
#End Region
#Region "Methods"
    Private Function GetDetailedFileInfo(ByVal sFile As String) As ArrayList
        Dim aReturn As ArrayList = New ArrayList()
        If (sFile.Length > 0) Then
            Try
                'Creating a ShellClass Object from the Shell32
                Dim sh As ShellClass = New ShellClass()
                'Creating a Folder Object from Folder that inculdes the File
                Dim Dir As Folder = sh.NameSpace(Path.GetDirectoryName(sFile))
                'Creating a new FolderItem from Folder that includes the File
                Dim item As FolderItem = Dir.ParseName(Path.GetFileName(sFile))
                'loop throw the Folder Items
                For i As Integer = 0 To 30
                    'read the current detail Info from the FolderItem Object
                    '(Retrieves details about an item in a folder. For example, its size, type, or the time of its last modification.)
                    ' some examples:
                    ' 0 Retrieves the name of the item.
                    ' 1 Retrieves the size of the item.
                    ' 2 Retrieves the type of the item.
                    ' 3 Retrieves the date and time that the item was last modified.
                    ' 4 Retrieves the attributes of the item.
                    ' -1 Retrieves the info tip information for the item.
                    Dim det As String = Dir.GetDetailsOf(item, i)
                    ' Create a helper Object for holding the current Information
                    ' an put it into a ArrayList
                    Dim oFileInfo As DetailedFileInfo = New DetailedFileInfo(i, det)
                    aReturn.Add(oFileInfo)
                Next
            Catch ex As Exception

            End Try
        End If
        Return aReturn
    End Function
#End Region

    Public Class DetailedFileInfo
        Dim iID As Integer = 0
        Dim sValue As String = ""
        Public Property ID() As Integer
            Get
                Return iID
            End Get
            Set(ByVal value As Integer)
                iID = value
            End Set
        End Property
        Public Property Value() As String
            Get
                Return sValue
            End Get
            Set(ByVal value As String)
                sValue = value
            End Set
        End Property
        Public Sub New(ByVal ID As Integer, ByVal Value As String)
            iID = ID
            sValue = Value
        End Sub
    End Class

End Class

 ===============================================================================
我所知道的属性:
0——文件名              1——文件大小         2——文件类型                  3——创建日期           4——修改日期
5——访问日期          6——                         7——是否在线                   8——用户名              9——作者
10——标题               11——主题               12——Category                 13——帧数               14——关键字

24——相机型号     25——拍摄日期          26——长*高                   27——长                     28——高

===============================================================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息