Previous  Home  Next

Make sure a path is terminated with a backslash

When you're dealing with paths, it's useful to be able to ensure that there's a path separator character at the end of the path. This function ensures that one's there.

Function SlashTerminate(sPath as String) as String
' Returns a string terminated with a path separator character
' Works on PC or Mac

	Dim PathSep As String
	#If Mac Then
		PathSep = ":"
	#Else
		PathSep = "\"
	#End If

	' Is the rightmost character a backslash?
	If Right$(sPath,1) <> PathSep Then
		' No; add a backslash
		SlashTerminate = sPath & PathSep
	Else
		SlashTerminate = sPath
	End If

End Function
Previous  Home  Next