< Public Function CombineFilePath (Path1 As String, Path2 As String) As String (?)

Comments

'Concatenates 2 paths, with or without a "\" in the middle as necessary

Public Function CombineFilePath (Path1 As String, Path2 As String) As String

    Dim TestChar As String
    
    'Remove trailing slash from first bit
    TestChar = Right(Path1, 1)
    If TestChar = "\" Or TestChar = "/" Then
        Path1 = TrimFrom(Path1, 0, 1)
    End If
    
    'Remove leading slash from second bit
    TestChar = Left(Path2, 1)
    If TestChar = "\" Or TestChar = "/" Then
        Path2 = TrimFrom(Path2, 1, 0)
    End If
    
    'Concatenate the two paths
    CombineFilePath = Path1 & "\" & Path2
    
    'Convert to windows-style slashes
    CombineFilePath = Replace(CombineFilePath, "/", "\")
End Function


Copying, Return to index