Archive: File/path last character evaluation, concatenation


File/path last character evaluation, concatenation
Learning lots every day about NSIS, so far I've got to say I'm pretty impressed. Especially very happy to see the divestment from .ini files (InstallOptions) in deference to native scripting (nsDialogs and in general).

Anyway, I know I'm doing some things inefficiently, as all beginnners do, but I have what I think is a simple question and I've not seen the magic header command or custom function/macro that makes this more 'elegant' , but its gotta be out there (?)

I have to evaluate a path from a text control to normalize it for use, in two ways:
1) If the path supplied did not have a trailing slash, append one.
2) In either case, append a subdirectory to the string
So there are two outputs I'm looking for, shown here as $1 and $5, respectively

StrCpy $1 "C:\somepath\" ;from input may or may not have trailing backslash
StrLen $2 $1
IntOp $3 $2 - 1
StrCpy $4 $1 "" $3 ; now i know the last char in $4
${If} $4 != "\"
StrCpy $5 "$1\SubDir\" ;Append Dir (case 2) "C:\somepath\Subdir\"
StrCpy $1 "$1\" ;normalize input (case 1) "C:\somepath\"
${Else}
StrCpy $0 "SubDir\" ;workaround(?) for concat of strings to avoid C:\somepath\\SubDir\
StrCpy $5 "$bkuppath_state$0" ;C:\somepath\Subdir\


This works, but it seems a bit...verbose. And looking ahead i see needing to evaluate this condition a lot.

Is there a better way? Teach me, i am in the throes of NSIS scripting consumption, and i need nourishment.

Thanks in advance for help!

Just put your code in a function so it accepts a path and return it with just one trailing slash.

Reading your Q is inspiring and written in a such a friendly colloquial tone that I think you'll get a better response from some major dude or forum king. Be sure to check back when others get a chance to see it and think it thru...


Your best bet is either a function or a macro. Functions cannot accept parameters, however. Macros accept parameters, but every call is saved separately in your installer, so the overall exe size would increase (very) slightly.