Get long file name from short file name 
Author Message
 Get long file name from short file name

Hi people,

Does anyone knows how I can get the long name of a file (win95) from its
short name?

Ex: C:\progra~1\budget.txt is in fact C:\Program Files\budget.txt

I need a way in Access97 (Visual Basic coding) to convert these shorts
names to long ones.... I've tried CURDIR(), DIR(), etc. but it doesn't
work!

Any idea? I know I'm out!

Jean



Fri, 31 Mar 2000 03:00:00 GMT  
 Get long file name from short file name

Just for fun, here's three functions, the first one returns the short
filename, the other two return the long filename.

'**************** Code Start *********************************
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA"
(ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal
cchBuffer As Long) As Long

'Returns the Path and File in short (8.3) format
'If the file doesn't exist returns ""
Function ShortName(lpszLongPath As String) As String
  Dim lpszShortPath As String
  Dim cchBuffer As Long
  Dim lngret As Long

  lpszLongPath = lpszLongPath
  lpszShortPath = String$(255, 0)
  cchBuffer = Len(lpszShortPath)

  lngret = GetShortPathName(lpszLongPath, lpszShortPath, cchBuffer)
  If lngret > cchBuffer Then
    lpszShortPath = String$(lngret, 0)
    cchBuffer = Len(lpszShortPath)
    lngret = GetShortPathName(lpszLongPath, lpszShortPath, cchBuffer)
  End If
  ShortName = Left(lpszShortPath, lngret)
End Function
'**************** Code End ***********************************

'**************** Code Start *********************************
Private Const MAX_PATH& = 260
Private Type FILETIME
  dwLowDateTime As Long
  dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
  dwFileAttributes As Long
  ftCreationTime As FILETIME
  ftLastAccessTime As FILETIME
  ftLastWriteTime As FILETIME
  nFileSizeHigh As Long
  nFileSizeLow As Long
  dwReserved0 As Long
  dwReserved1 As Long
  cFileName As String * MAX_PATH
  cAlternate As String * 14
End Type
Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
  (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long

'Returns the Path and File in Long format
'If the file doesn't exist returns ""
Function LongName(ByVal lpFileName As String) As String
  Dim lpFindFileData As WIN32_FIND_DATA
  Dim strRet As String
  Dim strTemp As String
  Dim strtemp2 As String
  Dim lngret As Long

  strtemp2 = lpFileName
  Do Until lngret = -1
    lngret = FindFirstFile(lpFileName, lpFindFileData)
    If lngret <> -1 Then
      strTemp = lpFindFileData.cFileName
      strTemp = Left(strTemp, InStr(strTemp, vbNullChar) - 1)
      Do Until Right(lpFileName, 1) = "\"
        lpFileName = Left(lpFileName, Len(lpFileName) - 1)
      Loop
      lpFileName = Left(lpFileName, Len(lpFileName) - 1)
      If strRet = "" Then
        strRet = strTemp
      Else
        strRet = strTemp & "\" & strRet
      End If
    End If
  Loop
  If strtemp2 <> lpFileName Then strRet = lpFileName & "\" & strRet
  LongName = strRet
End Function
'**************** Code End ********************************

Or this version uses the Dir function to get the long filename

'**************** Code Start  ********************************
'Returns the Path and File in Long format
'If the file doesn't exist returns ""
Function DirLongName(ByVal lpFileName As String) As String
  Dim strRet As String
  Dim strTemp As String
  Dim lngret As Long

  strTemp = Dir(lpFileName)
  strRet = strTemp
  If strRet <> "" Then
    Do Until strTemp = "."
      Do Until Right(lpFileName, 1) = "\"
        lpFileName = Left(lpFileName, Len(lpFileName) - 1)
      Loop
      lpFileName = Left(lpFileName, Len(lpFileName) - 1)
      strTemp = Dir(lpFileName, vbDirectory)
      If strTemp <> "." Then strRet = strTemp & "\" & strRet
    Loop
    strRet = lpFileName & "\" & strRet
  End If
  DirLongName = strRet
End Function
'**************** Code End ********************************

Quote:

>Hi people,

>Does anyone knows how I can get the long name of a file (win95) from its
>short name?

>Ex: C:\progra~1\budget.txt is in fact C:\Program Files\budget.txt

>I need a way in Access97 (visual basic coding) to convert these shorts
>names to long ones.... I've tried CURDIR(), DIR(), etc. but it doesn't
>work!

>Any idea? I know I'm out!

>Jean



Sat, 01 Apr 2000 03:00:00 GMT  
 Get long file name from short file name

You're a genius Terry!!!

Works wonderfully well!!!

THANKS!!!



Mon, 03 Apr 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting short file name from long file name:

2. Long File Names and Short File Names

3. Get Short File Name from Long File Name?

4. Long file names to short file name

5. Converting Long File Names to Short File Names

6. long file names to short file name

7. How to convert long file names to short file names

8. Api function to convert Long File Names To Short Dos File Names

9. Long File Names and Short File Names

10. Short File Name to Long File Name

11. Getting short file names instead of long filenames?

12. Getting Long file names from short

 

 
Powered by phpBB® Forum Software