Update to DetermineRelativePath function

This commit is contained in:
Michael J. Seiferling
2016-02-29 15:59:49 -06:00
parent de7a993abe
commit 4c7d36baef
+16 -14
View File
@@ -119,20 +119,22 @@ Public Class mgrPath
Dim iRemove As Integer = 0 Dim iRemove As Integer = 0
Dim iBackFolders As Integer = 0 Dim iBackFolders As Integer = 0
Dim bDeep As Boolean Dim bDeep As Boolean
Dim cPathChars As Char() = {"\", "/"} Dim cDS As Char = Path.DirectorySeparatorChar 'Set the directory seperator based on the OS
'We are working with a case insenstive file system, ensure a uniform case 'If we are working with a case insenstive file system, use a uniform case. **Look into removing this completely**
If cDS <> "/" Then 'Checking the seperator to determine OS is better than messing with enumerations that weren't always supported
sProcessPath = sProcessPath.ToLower sProcessPath = sProcessPath.ToLower
sSavePath = sSavePath.ToLower sSavePath = sSavePath.ToLower
End If
'We need to ensure we have a single trailing slash on the parameters 'We need to ensure we have a single trailing slash on the parameters
sProcessPath = sProcessPath.TrimEnd(cPathChars) sProcessPath = sProcessPath.TrimEnd(cDS)
sSavePath = sSavePath.TrimEnd(cPathChars) sSavePath = sSavePath.TrimEnd(cDS)
sProcessPath &= "/" sProcessPath &= cDS
sSavePath &= "/" sSavePath &= cDS
'Determines the direction we need to go, we always want to be relative to the process location 'Determines the direction we need to go, we always want to be relative to the process location
If sSavePath.Split(cPathChars).Length > sProcessPath.Split(cPathChars).Length Then If sSavePath.Split(cDS).Length > sProcessPath.Split(cDS).Length Then
sPath1 = sProcessPath sPath1 = sProcessPath
sPath2 = sSavePath sPath2 = sSavePath
bDeep = True bDeep = True
@@ -143,8 +145,8 @@ Public Class mgrPath
End If End If
'Build an array of folders to work with from each path 'Build an array of folders to work with from each path
sPath1Array = sPath1.Split(cPathChars) sPath1Array = sPath1.Split(cDS)
sPath2Array = sPath2.Split(cPathChars) sPath2Array = sPath2.Split(cDS)
'Take the shortest path and remove the common folders from both 'Take the shortest path and remove the common folders from both
For Each s As String In sPath1Array For Each s As String In sPath1Array
@@ -156,25 +158,25 @@ Public Class mgrPath
Next Next
'Remove the trailing slashes 'Remove the trailing slashes
sPath1 = sPath1.TrimEnd(cPathChars) sPath1 = sPath1.TrimEnd(cDS)
sPath2 = sPath2.TrimEnd(cPathChars) sPath2 = sPath2.TrimEnd(cDS)
'Determine which way we go 'Determine which way we go
If bDeep Then If bDeep Then
If sPath1.Length > 0 Then If sPath1.Length > 0 Then
iBackFolders = sPath1.Split(cPathChars).Length iBackFolders = sPath1.Split(cDS).Length
End If End If
sResult = sPath2 sResult = sPath2
Else Else
If sPath2.Length > 0 Then If sPath2.Length > 0 Then
iBackFolders = sPath2.Split(cPathChars).Length iBackFolders = sPath2.Split(cDS).Length
End If End If
sResult = sPath1 sResult = sPath1
End If End If
'Insert direction modifiers based on how many folders are left 'Insert direction modifiers based on how many folders are left
For i = 1 To iBackFolders For i = 1 To iBackFolders
sResult = ".." & Path.DirectorySeparatorChar & sResult sResult = ".." & cDS & sResult
Next i Next i
'Done 'Done