'---------------------------------------------------------------------------------------
' Module : modRelativePaths
' DateTime : 10/16/2005 02:19
' Author : Jeremy Blanchard
' Purpose :
'---------------------------------------------------------------------------------------
Option Explicit
'---------------------------------------------------------------------------------------
' Procedure : MakePathRelative
' DateTime : 10/16/2005 02:19
' Author : Jeremy Blanchard
' Purpose : Make sure to include either a \ at the end or a \filename.txt at the end
' of the paths
'---------------------------------------------------------------------------------------
'
Public Function MakePathRelative( _
ByVal sToMakeRelative As String, _
ByVal sAbsolutePath As String) As String
Dim i As Long
Dim j As Long
Dim sRel() As String
Dim sAbs() As String
Dim sReturn As String
sToMakeRelative = Replace$(sToMakeRelative, "/", "\", , , vbTextCompare)
sAbsolutePath = Replace$(sAbsolutePath, "/", "\", , , vbTextCompare)
sRel = Split(sToMakeRelative, "\", , vbTextCompare)
sAbs = Split(sAbsolutePath, "\", , vbTextCompare)
For i = 0 To UBound(sAbs) - 1
If sRel(i) = sAbs(i) Then
' Do nothing but increment i
Else
For j = i To UBound(sAbs) - 1
sReturn = sReturn & "..\"
Next j
Exit For
End If
Next i
For i = i To UBound(sRel)
sReturn = sReturn & sRel(i)
If i <> UBound(sRel) Then _
sReturn = sReturn & "\"
Next i
MakePathRelative = sReturn
End Function
'---------------------------------------------------------------------------------------
' Procedure : MakePathAbsolute
' DateTime : 10/16/2005 02:19
' Author : Jeremy Blanchard
' Purpose : Make sure to include either a \ at the end or a \filename.txt at the end
' of the paths
'---------------------------------------------------------------------------------------
'
Public Function MakePathAbsolute( _
ByVal sRelativePath As String, _
ByVal sAbsolutePath As String) As String
Dim i As Long
Dim j As Long
Dim sRel() As String
Dim sAbs() As String
Dim sReturn As String
Dim sPartial As String
sRelativePath = Replace$(sRelativePath, "/", "\", , , vbTextCompare)
sAbsolutePath = Replace$(sAbsolutePath, "/", "\", , , vbTextCompare)
sRel = Split(sRelativePath, "\", , vbTextCompare)
sAbs = Split(sAbsolutePath, "\", , vbTextCompare)
For i = 0 To UBound(sRel) - 1
If sRel(i) = ".." Then
' Do nothing but increment i
Else
For j = i To UBound(sRel)
sReturn = sReturn & sRel(j)
If j <> UBound(sRel) Then _
sReturn = sReturn & "\"
Next j
Exit For
End If
Next i
For i = 0 To UBound(sAbs) - 1 - i
sPartial = sPartial & sAbs(i)
If i <> UBound(sAbs) - i Then _
sPartial = sPartial & "\"
Next i
sReturn = sPartial & sReturn
MakePathAbsolute = sReturn
End Function