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/