Alternate Name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Larsen

    #1

    Alternate Name

    Does anyone know how I can get the Alternate Name for a file using VB? You
    know that short file names that are displayed when you issue the "DIR /X" DOS
    command. I can get the long file name using System.IO.FileI nfo class. Only
    problem is this class doesn't provide the alternate name (short name).
  • Tom Shelton

    #2
    Re: Alternate Name


    Greg Larsen wrote:[color=blue]
    > Does anyone know how I can get the Alternate Name for a file using VB? You
    > know that short file names that are displayed when you issue the "DIR /X" DOS
    > command. I can get the long file name using System.IO.FileI nfo class. Only
    > problem is this class doesn't provide the alternate name (short name).[/color]

    You use the GetShortPathNam e API function...

    Option Explicit On
    Option StrictOn

    Imports System.Text
    Imports Sytem.Runtime.I nteropServices

    ....

    Private Declare Auto Function GetShortPathNam e ( _
    ByVal lpszLongPath As String, _
    ByVal lpszShortPath As System.Text.Str ingBuilder, _
    ByVal cchBuffer As Integer) As Integer

    ....

    Public Function GetShortPathNam e (ByVal LongPathName As String) As
    String
    Dim buffer As New StringBuilder (260)

    Dim returnValue As Integer = GetShortPathNam e ( _
    LongPathName, buffer, buffer.Capacity )

    ' you should check the return here... If returnValue = 0, then
    there
    ' was a win32 error. If returnValue > buffer.Capacity , then you
    need to
    ' increase the buffer size to returnValue and call again.

    Return buffer.ToString ()
    End Function

    HTH,
    --
    Tom Shelton [MVP]

    Comment

    Working...