
Converting a Long FIleName to it's short equivalent (Both possible shorts)
Quote:
> Hey
> I'm trying to do some cleaning up and have some data whose paths were
> changed to their short form. This has happened twice (I finally found
> the protect!) Is there not an API call, function, sometinhg to show me
> what the 8 character equivalent would be??
> Unfortunately, I've ended up with both the 'closest to longname' and the
> 123456~8 formats.
> Any advice would be appreciated Thanks!
> Bill
Bill:
Try the following:
Private Declare Function GetShortPathName Lib "KERNEL32"
Alias "GetShortPathNameA" (ByVal lpszLongPath As String,
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As
Long
-------------------------------
Public Function GetShortFileName(ByVal FileName As String)
As String
'converts a long file and path name to old DOS format
'PARAMETERS
' FileName = the path or filename to convert
'RETURNS
' String = the DOS compatible name for that particular
FileName
Dim rc As Long
Dim ShortPath As String
Const PATH_LEN& = 164
'get the short filename
ShortPath = String$(PATH_LEN + 1, 0)
rc = GetShortPathName(FileName, ShortPath, PATH_LEN)
GetShortFileName = Left$(ShortPath, rc)
End Function
Jeff Hong YAN