This function will combine two path strings into one valid path. It basically just removes the need for you to worry about whether the strings end or begin with slashes or not.
Examples:
pathCombine("C:\Users\Brian","file.txt") = "C:\Users\Brian\file.txt"
pathCombine("C:\Users\Brian\","\Documents\file.txt") = "C:\Users\Brian\Documents\file.txt"
If you have Matrix 16 you can remove my implementation of trimRight$ and it will use the C one.
testTrim("Path/\ \", "\/ ")
testTrim("Hello World", "old")
testTrim("Alice", "Alice")
testTrim("Alice", "alice")
testPath("C:\Users\Brian","file.txt")
testPath("C:\Users\Brian\","\Documents\file.txt")
wait key
end
function testTrim(input$,trimmer$)
print input$ , "->" , trimRight$(input$,trimmer$)
endfunction
function testPath(a$,b$)
print a$ , "+" , b$ , "->" , pathCombine(a$, b$)
endfunction
//Combines two path strings into one valid path
function pathCombine(a as string, b as string)
local already
if (left$(b,1) = "/" or left$(b,1) = "\")
already = 1
endif
if (right$(a,1) = "/" or right$(a,1) = "\")
if (already)
a = trimRight$(a,"/\ ")
endif
already = 1
endif
if (already = 0)
a = a + "\" + b
else
a = a + b
endif
endfunction a
//Removes any string of the specified characters from the right side of input$
//Case sensitive
function trimRight$(input$, chars$)
local newEnd = len(input$)
local toss = 0
for c = len(input$) to 1 step -1
toss = 0
for i = 0 to len(chars$)
if mid$(chars$,i) = mid$(input$,c)
toss = 1
exit
endif
next i
if toss = 0
exit
else
newEnd = c
endif
next c
input$ = left$(input$, newEnd-1)
endfunction input$