Archive: How to remove trailing slash


How to remove trailing slash
How would one remove a trailing \ from a variable's last position? If this was C++, I'd just check if the last character was a \ and remove it...

I tried using WordReplace:


${WordReplace} "$R0" "\" "" "E-1" $R1


The problem I'm running into, is that if a variable holds just C:\, then it works fine (spits out C:). If the variable holds C:\Inetpub\wwwroot, it'll spit out C:\Inetpubwwwroot.

${WordReplace} "$R0" "\" "" "E}" $R1

That seems to work great. Knew I must've been missing something simple...


${WordReplace} is pretty heavy solution for this problem. This simple code will do the same thing.

; $R0 = your path

StrCpy $R1 "$R0" "" -1 ; this gets the last char
StrCmp $R1 "\" 0 +2 ; check if last char is '\'
StrCpy $R0 "$R0" -1 ; last char was '\', remove it