Rubrik: Dateisystem · Dateien allgemein | VB-Versionen: VB4, VB5, VB6 | 09.11.04 |
Datei-Beschreibungs-Info ermitteln Dieser Tipp verrät, wie sich die allgemeine Kurzbeschreibung einer Datei ermitteln lässt, so wie sie auch vom Windows Explorer angezeigt wird. | ||
Autor: Dieter Otter | Bewertung: | Views: 11.863 |
www.tools4vb.de | System: Win9x, WinNT, Win2k, WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Dieser Tipp verrät, wie sich die allgemeine Kurzbeschreibung einer Datei ermitteln lässt, so wie sie auch vom Windows Explorer angezeigt wird.
Fügen Sie hierzu nachfolgenden Code in ein Modul.
Option Explicit ' Benötigte API-Deklarationen Private Declare Function SHGetFileInfo Lib "shell32.dll" _ Alias "SHGetFileInfoA" ( _ ByVal pszPath As String, _ ByVal dwFileAttributes As Long, _ psfi As SHFILEINFO, _ ByVal cbFileInfo As Long, _ ByVal uFlags As Long) As Long Private Const SHGFI_TYPENAME = &H400 Private Const MAX_PATH = 260 Private Type SHFILEINFO hIcon As Long iIcon As Long dwAttributes As Long szDisplayName As String * MAX_PATH szTypeName As String * 80 End Type
' Standard-Dateibeschreibung ermitteln Public Function GetFileDescription(ByVal sFile As String) As String Dim oInfo As SHFILEINFO Call SHGetFileInfo(sFile, 0, oInfo, Len(oInfo), SHGFI_TYPENAME) GetFileDescription = TrimNull(oInfo.szTypeName) End Function
' Hilfsfunktion: String bei Null-Zeichen abschneiden Private Function TrimNull(ByVal sString As String) As String Dim nPos As Long nPos = InStr(sString, Chr$(0)) If nPos > 0 Then TrimNull = Left$(sString, nPos - 1) Else TrimNull = sString End If End Function
Aufrufbeispiel:
Label1.Caption = GetFileDescription("d:\test.txt")