Alternate Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.FileInfo class. Only
problem is this class doesn't provide the alternate name (short name).
 
Greg said:
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.FileInfo class. Only
problem is this class doesn't provide the alternate name (short name).

You use the GetShortPathName API function...

Option Explicit On
Option StrictOn

Imports System.Text
Imports Sytem.Runtime.InteropServices

....

Private Declare Auto Function GetShortPathName ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer

....

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

Dim returnValue As Integer = GetShortPathName ( _
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,
 
Back
Top