Archive: Path concatenation


Path concatenation
Call me Thicky McThick but... how do I concatenate path elements together?

I've got a path string and I want to add a subdirectory to that string but I don't know if it has a trailing backslash (\) or not. Easy-peasy - except I can't see how to check the last character of the source string?

I'm probably missing the obvious again, but I can't see anything in the documentation or by searching this forum.


Use StrCpy instruction to concatenate strings, StrCmp to check last symbol.


Tried that but can't see any way to specify an offset to StrCmp (or even to work out the length of the string)


4.9.8.1 StrCpy
user_var(destination) str [maxlen] [start_offset]
Sets the user variable $x with str. Note that str can contain other variables, or the user variable being set (concatenating strings this way is possible, etc). If maxlen is specified, the string will be a maximum of maxlen characters (if maxlen is negative, the string will be truncated abs(maxlen) characters from the end). If start_offset is specified, the source is offset by it (if start_offset is negative, it will start abs(start_offset) from the end of the string).

StrCpy $0 "a string" # = "a string"
StrCpy $0 "a string" 3 # = "a s"
StrCpy $0 "a string" -1 # = "a strin"
StrCpy $0 "a string" "" 2 # = "string"
StrCpy $0 "a string" "" -3 # = "ing"
StrCpy $0 "a string" 3 -4 # = "rin"

I had seen that but you made me think about solving the problem backwards - so rather than trying to compare a substring; copy out the bit to be tested and then compare that... A bit round about but this seems to work:

StrCpy $2 $1 "" -1
StrCmp $2 "\" +2
StrCpy $1 "$1\"
StrCpy $INSTDIR "$1New Sub Dir"


Thanks.