Does anyone have any idea how I access the current description for a file type? For example, if I was looking at a file named 'text.xls' I would like to be able to get 'Microsoft Excel Worksheet' back.
Many thanks
Geoff Soper
Printable View
Does anyone have any idea how I access the current description for a file type? For example, if I was looking at a file named 'text.xls' I would like to be able to get 'Microsoft Excel Worksheet' back.
Many thanks
Geoff Soper
Here's an example which does that and a little more:
VB Code:
Const SHGFI_DISPLAYNAME = &H200 Const SHGFI_TYPENAME = &H400 Const MAX_PATH = 260 Private Type SHFILEINFO hIcon As Long ' out: icon iIcon As Long ' out: icon index dwAttributes As Long ' out: SFGAO_ flags szDisplayName As String * MAX_PATH ' out: display name (or path) szTypeName As String * 80 ' out: type name End Type 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 Sub Form_Paint() 'KPD-Team 1999 'URL: [url]http://www.allapi.net/[/url] 'E-Mail: [email][email protected][/email] Dim FI As SHFILEINFO 'Get file info SHGetFileInfo "c:\autoexec.bat", 0, FI, Len(FI), SHGFI_DISPLAYNAME Or SHGFI_TYPENAME Me.Cls Me.Print "Filename: Autoexec.bat" Me.Print "Typename: " + StripTerminator(FI.szTypeName) Me.Print "Displayname: " + StripTerminator(FI.szDisplayName) End Sub 'This fucntion is used to strip al the unnecessary chr$(0)'s Function StripTerminator(sInput As String) As String Dim ZeroPos As Integer 'Search the position of the first chr$(0) ZeroPos = InStr(1, sInput, vbNullChar) If ZeroPos > 0 Then StripTerminator = Left$(sInput, ZeroPos - 1) Else StripTerminator = sInput End If End Function
or you can try this:
VB Code:
Private Sub Command1_Click() 'Add a reference to the 'Microsoft Scripting Runtime' (scrrun.dll) Dim fso As New FileSystemObject Dim fle As File Set fle = fso.GetFile("C:\autoexec.bat") Debug.Print fle.Attributes Debug.Print fle.DateCreated Debug.Print fle.Size Debug.Print fle.Type Debug.Print fle.Path Debug.Print fle.DateLastAccessed Debug.Print fle.DateLastModified Debug.Print fle.Drive Debug.Print fle.Name Debug.Print fle.ParentFolder Debug.Print fle.Path Debug.Print fle.ShortName Debug.Print fle.ShortPath End Sub
Regards...