Long names from short. 
Author Message
 Long names from short.

I asked a question about expanding short file names into their full long
file name version several months ago.  There was no solution offered,
just a couple of requests to pass on the solution when and if I found
one.  

The only solution I could think of was to reconstruct the entire path
from drive through file name by enumerating the folders and subfolders
until a short form match for each component was found.  I used the same
approach for the file within its folder.  It makes for a fairly long
function just to do what seems a simple cosmetic housekeeping job.  I
figure if I have missed something obvious, someone will show me the
error of my ways, something like the way I learned to play solitaire as
a Boy Scout when lost in the woods. (So that I could ask direction of
the kind soul who appears out of nowhere to tell me to play the black
seven on the red eight.)

Well, I finally had enough spare time to play with the problem and offer
the following function for consideration...

' Expands a file's Short form PathName into a Long one.
'
' Tom Lavedas, May 1999
'
Function LongPathName(sName) ' As String
  Dim colF, cF, _
      sShortFolderName, sBaseName, sPathName, sShortPath
  sPathName = ""
  On Error Resume Next
    sPathName = objFS.GetFile(sName).ShortPath
  On Error Goto 0 ' (a VB construct, undocumented in VBScript)
  if sPathName <> "" Then
    sShortFolderName = objFS.GetFolder(sPathName  & "\..").Path
    sPathName = objFS.GetDrive(Left(sName,Instr(sPathName , _
               ":"))).RootFolder
    Do ' Enumerate folders and match to named file's path
      Set colF = objFS.GetFolder(sPathName).Subfolders
      For Each cF in colF
        sShortPath = cF.ShortPath
        if Instr(sName, sShortPath) > 0 Then
          sPathname = cF.Path
          Exit For
        End if
      Next
    Loop Until sShortPath = sShortFolderName
    sBaseName = objFS.GetFile(sName).ShortName
    Set colF = objFS.GetFolder(sShortFolderName).Files
    For Each cF in colF ' Enumerate files and match to named file
      if cF.ShortName = sBaseName Then
        LongPathName = sPathname & "\" & cF.Name
        Exit For
      End if
    Next
    Set cF = Nothing
    Set colF = Nothing
  Else
    LongPathName = ""
  End if
End Function

Tom Lavedas
-----------
http://www.*-*-*.com/ ~tglbatch/



Sun, 04 Nov 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Converting Long File Names to Short File Names

2. Getting short file name from long file name:

3. Converting Long File Names to Short File Names

4. Converting Short File Names to Long File Names

5. Converting Paths having short name to long versions

6. registry %1 argument and short/long path names

7. Affecting Long Edge/Short Edge feed in PostScript?

8. Convert Long Path to Short

9. Long File Names in ASP ... Convert with VBScript to Short File Names

10. FSO short name problem

11. how to get short path name

12. Get Short File Name in VBScript

 

 
Powered by phpBB® Forum Software