Function GetRelativePath(sFrom, sTo)
GetRelativePath = ""
sFromTmp = ""
sToTmp = ""
sTmp = ""
bFirst = True
Do While Len(sFrom) > Len(sFromTmp) Or Len(sTo) > Len(sToTmp)
If Len(sFrom) > Len(sFromTmp) Then
If Not bFirst Then sFrom = Right(sFrom, Len(sFrom) - Len(sFromTmp) - 1)
sFromTmp = GetLeftPart(sFrom)
Else
sFrom = ""
sFromTmp = ""
End If
If Len(sTo) > Len(sToTmp) Then
If Not bFirst Then sTo = Right(sTo, Len(sTo) - Len(sToTmp) - 1)
sToTmp = GetLeftPart(sTo)
Else
sTo = ""
sToTmp = ""
End If
If bFirst And sFromTmp <> sToTmp Then
Exit Function ' Нет общего корня
Else
bFirst = False
End If
If Len(GetRelativePath) > 0 Or sFromTmp <> sToTmp Then
If Len(sFromTmp) > 0 Then
If Len (GetRelativePath) > 0 Then
GetRelativePath = GetRelativePath & "\.."
Else
GetRelativePath = GetRelativePath & ".."
End If
End If
If Len(sToTmp) > 0 Then
If Len(sTmp) > 0 Then
sTmp = sTmp & "\" & sToTmp
Else
sTmp = sTmp & sToTmp
End If
End If
End If
Loop
If Len(sTmp) > 0 Then GetRelativePath = GetRelativePath & "\" & sTmp
If 0 = Len(GetRelativePath) Then GetRelativePath = "."
End Function
Function GetLeftPart(sPath)
For i = 1 To Len(sPath)
If "\" = Mid(sPath, i, 1) Then
GetLeftPart = Left(sPath, i - 1)
Exit Function
End If
Next
GetLeftPart = sPath
End Function