Archive: Help with StrCpy


Help with StrCpy
I'm trying to get the newest directory created and stored into a variable, but I can't seem to figure out how to do that.

My code below runs a specific DIR command in DOS and returns a bunch of directories. The top most will be the newest directory and is what is returned by the GetFirstStrPart function.

What I'd like to do is take that popped $R0 value and assign it to something like $NewestDir, but when I do the StrCpy, it errors out.

Any ideas?

Function InstallNewVersionsPost

ReadEnvStr $0 COMSPEC
nsExec::ExecToStack '$0 /C "dir g:\ /o-d/ad/b"'
Pop $0 # return value/error/timeout
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
Push $1
Call GetFirstStrPart
Pop "$R0"
;StrCpy $R0 $NewestDir
ReadINIStr ${TEMP1} "$PLUGINSDIR\test.ini" "Field 7" "State"
${If} ${TEMP1} == "1"
ExecWait '"G:\$R0\mysoftware\DISK1\SETUP.EXE" -s -f1$PLUGINSDIR\install.iss'
${EndIf}

FunctionEnd

Function GetFirstStrPart
Exch $R0
Push $R1
Push $R2
StrLen $R1 $R0
IntOp $R1 $R1 + 1
loop:
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 -$R1
StrCmp $R2 "" exit2
StrCmp $R2 "$\r" exit1 ; Change " " to "\" if ur inputting dir path str
Goto loop
exit1:
StrCpy $R0 $R0 -$R1
exit2:
Pop $R2
Pop $R1
Exch $R0
FunctionEnd

I'm not sure what Pop "$R0" ends up doing after compilation, but I'd try removing the quotes?


Originally posted by MSG
I'm not sure what Pop "$R0" ends up doing after compilation, but I'd try removing the quotes?
Thanks for the idea, but that didn't work.

I noticed a problem with what I copy/pasted. I think the commented out strcpy should be
StrCpy $NewestDir $R0


Either way I tested it, I get this in my output window:

Pop: $R0
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]
Error in script "C:\Documents and Settings\myuser\Desktop\NSIS Scripts\messing_around.nsi" on line 346 -- aborting creation process

Well you can of course just Pop $NewestDir, but that doesn't explain why StrCpy is complaining. If the NewestDir variable wasn't declared it should give a different error... And it shouldn't be because the string ends with a \, since that's a compile-time issue and registers are only filled at runtime. No, I can't see why it would break down.


You will get that error if the variable has not been declared. You will get a similar error for Pop $UndeclaredVar.

Stu


Eh? I tried it myself, and the compiler just gave a 'warning: Unknown variable, line ignored'.


Using 2.45:

StrCpy $NewestDir $R0
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]

Pop $NewestDir
Usage: Pop $(user_var: output)

Stu


After declaring the variable, I was able to do a StrCpy.

Thanks for the help!