Results 1 to 3 of 3

Thread: Finding the description associated with a file type

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    5

    Finding the description associated with a file type

    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

  2. #2
    Si_the_geek
    Guest
    Here's an example which does that and a little more:

    VB Code:
    1. Const SHGFI_DISPLAYNAME = &H200
    2. Const SHGFI_TYPENAME = &H400
    3. Const MAX_PATH = 260
    4. Private Type SHFILEINFO
    5.     hIcon As Long                      '  out: icon
    6.     iIcon As Long          '  out: icon index
    7.     dwAttributes As Long               '  out: SFGAO_ flags
    8.     szDisplayName As String * MAX_PATH '  out: display name (or path)
    9.     szTypeName As String * 80         '  out: type name
    10. End Type
    11. 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
    12.  
    13. Private Sub Form_Paint()
    14.     'KPD-Team 1999
    15.     'URL: [url]http://www.allapi.net/[/url]
    16.     'E-Mail: [email][email protected][/email]
    17.     Dim FI As SHFILEINFO
    18.     'Get file info
    19.     SHGetFileInfo "c:\autoexec.bat", 0, FI, Len(FI), SHGFI_DISPLAYNAME Or SHGFI_TYPENAME
    20.     Me.Cls
    21.     Me.Print "Filename: Autoexec.bat"
    22.     Me.Print "Typename: " + StripTerminator(FI.szTypeName)
    23.     Me.Print "Displayname: " + StripTerminator(FI.szDisplayName)
    24. End Sub
    25. 'This fucntion is used to strip al the unnecessary chr$(0)'s
    26. Function StripTerminator(sInput As String) As String
    27.     Dim ZeroPos As Integer
    28.     'Search the position of the first chr$(0)
    29.     ZeroPos = InStr(1, sInput, vbNullChar)
    30.     If ZeroPos > 0 Then
    31.         StripTerminator = Left$(sInput, ZeroPos - 1)
    32.     Else
    33.         StripTerminator = sInput
    34.     End If
    35. End Function

  3. #3
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    or you can try this:
    VB Code:
    1. Private Sub Command1_Click()
    2.     'Add a reference to the 'Microsoft Scripting Runtime' (scrrun.dll)
    3.     Dim fso As New FileSystemObject
    4.     Dim fle As File
    5.     Set fle = fso.GetFile("C:\autoexec.bat")
    6.     Debug.Print fle.Attributes
    7.     Debug.Print fle.DateCreated
    8.     Debug.Print fle.Size
    9.     Debug.Print fle.Type
    10.     Debug.Print fle.Path
    11.     Debug.Print fle.DateLastAccessed
    12.     Debug.Print fle.DateLastModified
    13.     Debug.Print fle.Drive
    14.     Debug.Print fle.Name
    15.     Debug.Print fle.ParentFolder
    16.     Debug.Print fle.Path
    17.     Debug.Print fle.ShortName
    18.     Debug.Print fle.ShortPath
    19. End Sub

    Regards...
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width