Dateityp ermitteln
[Windows 95/98/NT/2000]

13.11.1999


Die Detailanzeige des Windows-Explorers beschreibt jede Datei
    mit einem Dateityp.
    Beispielsweise: Bootlog.txt - Textdatei

    Der nachfolgende Code ermittelt diesen Dateityp:

ERFORDERLICHE OBJEKTE
   1 DriveListBox (Drive1)
   1 DirListBox (Dir1)
   1 FileListBox (File1)
   1 Label (Label1)
 FORM-CODE
   Private Type SHFILEINFO
      hIcon As Long
      iIcon As Long
      dwAttributes As Long
      szDisplayName As String * 260
      szTypeName As String * 80
   End Type
   Private Declare Function SHGetFileInfo Lib "Shell32" Alias _
      "SHGetFileInfoA" (ByVal pszPath As Any, _
      ByVal dwFileAttributes As Long, psfi As SHFILEINFO, _
      ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
   Function GetStrFromBuffer(szStr As String) As String
      If InStr(szStr, vbNullChar) Then
         GetStrFromBuffer = Left$(szStr, InStr(szStr, _
            vbNullChar) - 1)
      Else
         GetStrFromBuffer = szStr
      End If
   End Function
   Private Function GetTypeName(sFilePath As String)
      Dim FileInfo As SHFILEINFO
      If SHGetFileInfo(ByVal sFilePath, 0&, FileInfo, _
        Len(FileInfo), &H400&) Then
           If InStr(FileInfo.szTypeName, vbNullChar) > 1 Then
              GetTypeName = GetStrFromBuffer(FileInfo.szTypeName)
           Else
             GetTypeName = "unbelannter Typ"
           End If
      End If
   End Function
   Private Sub Dir1_Change()
      File1.Path = Dir1.Path
   End Sub
   Private Sub Drive1_Change()
      Dir1.Path = Drive1.Drive
   End Sub
   Private Sub File1_Click()
      Dim Dateiname As String
      Dateiname = File1.Path
      If Right(Dateiname, 1) <> "\" Then _
         Dateiname = Dateiname & "\"
      Dateiname = Dateiname & File1.FileName
      Label1.Caption = GetTypeName(Dateiname)
   End Sub
 

 

Download - 2 KB