Skip to content
⌘ NSIS Forum Archive

FindFirst and variables?

5 posts

ajrjaneway#

FindFirst and variables?

I'm writing an installer where I want to copy files from an old installation to a new user location. I don't know the names of all the folders, because they will vary from user to user, so I'm using FindFirst, FindNext, and FindClose to get the list of folders. However, it doesn't seem to recognize when I use a variable in FindFirst. I'm wondering if it is because I'm doing it from within an If or if it's something else. I can get it to work if I change the outpath to the previous installation folder, but I would like to know why it doesn't work with the variable.

Here is the pertinent code. I'm not doing any copying yet, because I wanted to be sure I could find the folders first.

; Check to see if the old version exists. If it does, we need to do some other things
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${OLDAPPNAME}" "UninstallString"

${If} $R0 != 0
; copy files from the old installation if the user approves
; get the pathname from the path to the uninstaller
${GetParent} $R0 $R1
MessageBox MB_OKCANCEL \
"${OLDAPPNAME} is installed. $\n$\nClick `OK` to copy the \
user files from the previous installation to the new user area \
or `Cancel` to continue this installation without copying \
from $R1." \
IDOK docopy IDCANCEL cont

docopy:
; copy the obit data file
CopyFiles $R1\obit.dat $ODTDIR\appdata

; create the Sent folder and copy the old installation data
CreateDirectory "$ODTDIR\appdata\Sent"
CopyFiles $R1\Sent\* $ODTDIR\appdata\Sent

var /GLOBAL OLDDIR
StrCpy $OLDDIR $R1
DetailPrint $R1
DetailPrint $OLDDIR

; look for any newspaper folders and copy those entries
;
FindFirst $0 $1 '$R1\*.*'
loop:
StrCmp $1 "" done
${If} ${FileExists} '$1\*.*"'
StrCmp $1 "." next
StrCmp $1 ".." next
StrCmp $1 "Sent" next
${ElseIf} ${FileExists} $1
Goto next
${Else}
Goto next
${EndIf}
DetailPrint "Subdir found: $1"
next:
FindNext $0 $1
Goto loop
done:
FindClose $0

cont:
${Endif}
ajrjaneway#
I take your point and if I get this to work right, I'll do the right FileExists.

My point is that $R1 is completely empty when FindFirst is called. I've used the DetailPrint right before to verify that $R1 is non-empty (e.g. it equals C:\Program Files\Obituary Filer), but when FindFirst is called, $1 comes back empty. I've tried used FindFirst with $R1 and $OLDDIR and I don't understand why in either case, $1 comes up empty. I'm getting around it by doing SetOutPath to $R1 and then just doing FindFirst $0 $1 *.* and that works fine.
ajrjaneway#
Okay, I must've had a typo or something first time I tried, because now it works. I'm sorry -- I guess I'm off my game. Anyway, now this works:

docopy:
; copy the obit data file
CopyFiles $R1\obit.dat $ODTDIR\appdata

; Look for any newspaper folders and copy those entries
; to the appdata folder, the Sent folder will be included.
FindFirst $0 $1 $R1\*.*
loop:
StrCmp $1 "" done
${If} ${FileExists} $R1\$1\*.*
StrCmp $1 "." next
StrCmp $1 ".." next
${ElseIf} ${FileExists} $R1\$1
Goto next
${Else}
Goto next
${EndIf}
CreateDirectory $ODTDIR\appdata\$1
CopyFiles $R1\$1\*.* $ODTDIR\appdata\$1
next:
FindNext $0 $1
Goto loop
done:
FindClose $0

Thank you for your patience.