8.3 file name to Long file name 
Author Message
 8.3 file name to Long file name

How can I convert a shortened long file name back to its original long name?

For example, if the original long name is
   my document.doc

but the name I'm being sent is
   mydocu~1.doc

How can I get the original name back?  Assuming, of course that the
file still exists.

How can I do the same for folder names?
--
Don Sayler
for email reponses, remove
'do.not.spam.me.' from my return address



Wed, 18 Jun 1902 08:00:00 GMT  
 8.3 file name to Long file name


Quote:
> How can I convert a shortened long file name back to its original
long name?

> For example, if the original long name is
>    my document.doc

> but the name I'm being sent is
>    mydocu~1.doc

> How can I get the original name back?  Assuming, of course that the
> file still exists.

> How can I do the same for folder names?

There is a GetLongPathName API call but it did not exist in the first
couple of Win95 versions so it is not always the best choice.  You can
also use FindFirstFile/FindClose API calls to get various info
including the long name.

In the end, the easiest is probably
sLongName=Dir$(sShortName,vbDirectory)

--
Please reply via the newsgroup only

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 8.3 file name to Long file name
Hi Don,

Here's one way of doing it.

*** Start of Code

Public Function GetLongFilePath(Path As String) As String
 On Error GoTo ErrorHandler
 ' - Path string must be a fully qualified path (i.e.
C:\Mydocu~1\testlo~1.txt")
 '   including DRIVE:\FOLDERS (If Any)\File (If any)
 ' - Does not support wildcards
 ' - Path strings that do not contain a trailing backslash will
 '   be treated as file paths, those that do contain a trailing
 '   backslash will be treated as folder paths.
 Dim avarPaths As Variant ' Stores each segment of the path
 Dim lngPathCounter As Long ' Counter for the path array
 Dim strLongPath As String ' The long file/folder path to be returned
 Dim strPath As String ' Holds the results of the DIR function for the
current path in the array
 Dim lngLBound As Long ' Holds the LBound of the path array
 Dim lngUBound As Long ' Holds the UBound of the path array

 avarPaths = Split(Path, "\") ' Split the path string into its constituent
drive/paths/file
 lngLBound = LBound(avarPaths) ' Store the lowest element of the array
 lngUBound = UBound(avarPaths) ' Store the highest element of the array
 strLongPath = avarPaths(lngLBound) & "\" ' The drive letter should be the
first element, so store it as the first part of the long path
 For lngPathCounter = lngLBound + 1 To lngUBound - 1 ' Count from the first
element after the drive letter, to the last element before the filename (or
the empty string if we are expanding a folder path)
  strPath = Dir(strLongPath & avarPaths(lngPathCounter), vbDirectory) ' See
if we can find this folder
  If strPath <> "" Then ' We found either a folder or a file
   strLongPath = strLongPath & strPath ' Add the path we just found to the
full long path
   If Not GetAttr(strLongPath) And vbDirectory Then ' Check to see if the
path we found was indeed a directory, if this test succeeds, we found a FILE
and not a directory
    Err.Raise 76 ' Raise a "Path Not Found" error, because we're looking for
a folder and not a file at this point.
   End If
   strLongPath = strLongPath & "\" ' Append a trailing backslash to the long
path.
  Else ' No folder/file was found at this path,
   Err.Raise 76 ' So raise a "Path Not Found" error.
  End If
 Next lngPathCounter ' Loop through the folders in the array
 If avarPaths(lngUBound) <> "" Then ' If this not blank, we must search for
the file, otherwise, our work is done!
  strPath = Dir(strLongPath & avarPaths(lngUBound), vbArchive Or vbHidden Or
vbReadOnly Or vbSystem) ' Test for the existance of the file
  If strPath <> "" Then ' File exists
   strLongPath = strLongPath & strPath ' Append the long file name to the
long path
  Else ' File doesn't exist
   Err.Raise 53 ' Raise a "File not found" error
  End If
 End If
 GetLongFilePath = strLongPath ' Pass the long path to the function
 Exit Function
ErrorHandler:
 Err.Raise Err.Number
End Function

*** End of Code


Quote:
> How can I convert a shortened long file name back to its original long
name?

> For example, if the original long name is
>    my document.doc

> but the name I'm being sent is
>    mydocu~1.doc

> How can I get the original name back?  Assuming, of course that the
> file still exists.

> How can I do the same for folder names?
> --
> Don Sayler
> for email reponses, remove
> 'do.not.spam.me.' from my return address



Thu, 06 Mar 2003 14:39:33 GMT  
 8.3 file name to Long file name
Don, here's a routine that does it through the API which is probably
preferred, as well as an improved Error Handler in the Non-API version I
sent in the last message, in case you don't want to use API calls.

*** API Version Start of Code
Option Explicit

Private Declare Function GetLongPathName Lib "kernel32" Alias
"GetLongPathNameA" (ByVal lpShortPath As String, ByVal lpLongPath As String,
ByVal nBufferLength As Long) As Long
Private Const MAX_PATH = 260

Private Function GetLongFilePath(Path As String) As String
 On Error GoTo ErrorHandler
 ' Pass a short folder/file string to Path, and this will return the long
version.
 ' i.e. C:\MyDocu~1\ becomes C:\My Documents
 ' If you include a trailing backslash, it will be remain, if not, it will
not be added.
 Dim strLongPath As String ' Stores the Long folder/file path
 Dim strShortPath As String '
 Dim lngBufferLength As Long

 strLongPath = Space(MAX_PATH) ' Prepare the Long path buffer
 lngBufferLength = GetLongPathName(Path & Chr(0), strLongPath,
Len(strLongPath)) ' Try to get the long path
 If lngBufferLength > 0 Then ' If so, then we have a path! if not, the
path/file does not exist
  If lngBufferLength > Len(strLongPath) Then ' Wasn't a big enough buffer!
must resize and recall
   strLongPath = Space(lngBufferLength) ' Resize the buffer to the required
size
   lngBufferLength = GetLongPathName(Path & Chr(0), strLongPath,
Len(strLongPath)) ' Recall the API
  End If
  strLongPath = Left(strLongPath, lngBufferLength) ' Trim any extra
characters off the long path buffer
 Else ' Path/File does not exist
  Err.Raise 53 ' Raise 'File not found" error
 End If
 GetLongFilePath = strLongPath ' Return the long path
 Exit Function ' Leave before the error handler

ErrorHandler:
 If Err.Number = 53 Then ' File not found
  MsgBox Err.Description & vbCrLf & "'" & Path & "'", vbExclamation +
vbOKOnly, "GetLongFilePath Error"
 Else ' Unhandled error...uh oh
  MsgBox "Unhandled error in GetLongFilePath: " & vbCrLf & Err.Description,
vbCritical + vbOKOnly, "GetLongFilePath Error"
 End If
End Function

*** API Version END of code

*** Non-API Version Start of code

Public Function GetLongFilePath(Path As String) As String
 On Error GoTo ErrorHandler
 ' - Path string must be a fully qualified path (i.e.
C:\Mydocu~1\testlo~1.txt")
 '   including DRIVE:\FOLDERS (If Any)\File (If any)
 ' - Does not support wildcards
 ' - Path strings that do not contain a trailing backslash will
 '   be treated as file paths, those that do contain a trailing
 '   backslash will be treated as folder paths.
 Dim avarPaths As Variant ' Stores each segment of the path
 Dim lngPathCounter As Long ' Counter for the path array
 Dim strLongPath As String ' The long file/folder path to be returned
 Dim strPath As String ' Holds the results of the DIR function for the
current path in the array
 Dim lngLBound As Long ' Holds the LBound of the path array
 Dim lngUBound As Long ' Holds the UBound of the path array

 avarPaths = Split(Path, "\") ' Split the path string into its constituent
drive/paths/file
 lngLBound = LBound(avarPaths) ' Store the lowest element of the array
 lngUBound = UBound(avarPaths) ' Store the highest element of the array
 strLongPath = avarPaths(lngLBound) & "\" ' The drive letter should be the
first element, so store it as the first part of the long path
 For lngPathCounter = lngLBound + 1 To lngUBound - 1 ' Count from the first
element after the drive letter, to the last element before the filename (or
the empty string if we are expanding a folder path)
  strPath = Dir(strLongPath & avarPaths(lngPathCounter), vbDirectory) ' See
if we can find this folder
  If strPath <> "" Then ' We found either a folder or a file
   strLongPath = strLongPath & strPath ' Add the path we just found to the
full long path
   If Not GetAttr(strLongPath) And vbDirectory Then ' Check to see if the
path we found was indeed a directory, if this test succeeds, we found a FILE
and not a directory
    Err.Raise 76 ' Raise a "Path Not Found" error, because we're looking for
a folder and not a file at this point.
   End If
   strLongPath = strLongPath & "\" ' Append a trailing backslash to the long
path.
  Else ' No folder/file was found at this path,
   Err.Raise 76 ' So raise a "Path Not Found" error.
  End If
 Next lngPathCounter ' Loop through the folders in the array
 If avarPaths(lngUBound) <> "" Then ' If this not blank, we must search for
the file, otherwise, our work is done!
  strPath = Dir(strLongPath & avarPaths(lngUBound), vbArchive Or vbHidden Or
vbReadOnly Or vbSystem) ' Test for the existance of the file
  If strPath <> "" Then ' File exists
   strLongPath = strLongPath & strPath ' Append the long file name to the
long path
  Else ' File doesn't exist
   Err.Raise 53 ' Raise a "File not found" error
  End If
 End If
 GetLongFilePath = strLongPath ' Pass the long path to the function
 Exit Function ' Leave before the error handler

ErrorHandler:
 Select Case Err.Number
 Case 53, 76 ' File not found, Path not found
  MsgBox Err.Description & vbCrLf & "'" & Path & "'", vbExclamation +
vbOKOnly, "GetLongFilePath Error"
 Case 9
  MsgBox "No path to expand.", vbExclamation + vbOKOnly, "GetLongFilePath
Error"
 Case Else ' Unhandled error...uh oh
  MsgBox "Unhandled error in GetLongFilePath: " & vbCrLf & Err.Number & " -
" & Err.Description, vbCritical + vbOKOnly, "GetLongFilePath Error"
 End Select
End Function

*** NON-API Version End of code


Quote:
> How can I convert a shortened long file name back to its original long
name?

> For example, if the original long name is
>    my document.doc

> but the name I'm being sent is
>    mydocu~1.doc

> How can I get the original name back?  Assuming, of course that the
> file still exists.

> How can I do the same for folder names?
> --
> Don Sayler
> for email reponses, remove
> 'do.not.spam.me.' from my return address



Wed, 18 Jun 1902 08:00:00 GMT  
 8.3 file name to Long file name
Just found out the API version works only in Windows 98 and Windows 2000, so
you might want to avoid it unless you are sure that your users will only be
using Win98 or 2000 (or Windows ME I would presume)...


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Long file names to 8.3 File names convertion

2. Getting DOS 8.3 path from Windows long file name

3. vb4: getting 8.3 filename from long file name

4. Convert Long File Name to 8.3 Notation

5. ODBC to CSV Text files Fails if name longer than 8.3

6. converting long file names into 8.3 Dos with VB5

7. How to get short DOS 8.3 file names from long filenames

8. Add discriptive comments list to file 8.3 file names

9. Can't Get full File name for Long file names

10. Get long file name from short file name

11. Long File Names and Short File Names

12. Get Short File Name from Long File Name?

 

 
Powered by phpBB® Forum Software