'===================================================================================================================================
Public Function AddBackSlash(ByVal tsPath As String) As String
'===================================================================================================================================
' Purpose : Ensures the given path string has backslash at the end.
' Description : Checks if the passed parameter's data type match those of the Function's argument; if not – throws error message
' and returns unchanged parameter.
' Checks if it's an empty string, if it is - returns it As-Is.
' Checks if it's only a file name, if it is - returns it As-Is.
' Checks the given parameter-string in case it's full path to a file, cuts off the file name if it is.
' Checks if the given parameter-string has backslash at the end, adds it if it has not.
' Parameters : Path as String - mandatory
' Returns : Path with the backslash at the end, as String.
' Side effects : None.
' Notes : 1. Generic, applies with .NET Framework ver. 1.1, .NET Core 1.0, .NET Standard 1.0 and higher.
' 2. Verbose on errors, silent otherwise.
' Author : Ilya
' Revisions : 2020-03-09 by Ilya – started 1st draft.
'===================================================================================================================================
Dim lsPath As String = "", lsRet As String = ""
' Parameter's verification
If VarType(tsPath) <> VariantType.String Then
MsgBox("Invalid parameter passed: " & Chr(34) & "tsPath" & Chr(34) & " must be of type String", MsgBoxStyle.Critical, "Fatal Error: INVALID PARAMETER")
Return lsRet
End If
If String.IsNullOrEmpty(tsPath) Then
Return lsRet
End If
If Path.GetFileName(tsPath) <> "" And Path.GetExtension(tsPath) <> "" Then 'Path + File name? Strip off that latter
lsPath = tsPath.Replace(Path.GetFileName(tsPath), "")
Else
lsPath = tsPath
End If
If String.IsNullOrEmpty(lsPath) Then ' Only the file name was passed? Return blank string
Return lsPath
End If
' Check for the closing backslash
If Strings.Right(lsPath, 1) <> Path.DirectorySeparatorChar Then
lsRet = lsPath & Path.DirectorySeparatorChar
Else
lsRet = lsPath
End If
Return lsRet
End Function
'===================================================================================================================================