Hi Kim,
This VBA function takes an ordinary (long) filespec and returns the
short path to the same file. It seems to work properly but hasn't been
exhaustively tested.
Function GetShortPath(ByVal FileSpec As String, _
Optional FailOnError As Boolean = False)
Dim fso As Object
Dim oFile As Object
Dim oFolder As Object
Dim S As String
Dim Buf As String
On Error GoTo ErrHandler:
Set fso = CreateObject("Scripting.FileSystemObject")
'Get a handle on the file
Set oFile = fso.GetFile(FileSpec)
Do
FileSpec = fso.GetParentFolderName(FileSpec)
If Len(FileSpec) = 0 Then Exit Do
Set oFolder = fso.GetFolder(FileSpec)
Buf = oFolder.ShortName & "\" & Buf
Loop
GetShortPath = oFile.Drive & Buf & oFile.ShortName
Exit Function
ErrHandler:
If FailOnError Then
Err.Raise Err.Number, "GetShortPath()", _
Err.Description & vbCrLf & "[In GetShortPath() function]", _
Err.HelpFile, Err.HelpContext
Else
Err.Clear
GetShortPath = ""
End If
End Function
On Fri, 18 Aug 2006 15:51:28 +1000, Kim.Baker@exemail.com.au wrote:
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
|