Old 11th April 2016, 23:43   #1
ajrjaneway
Junior Member
 
Join Date: Feb 2016
Posts: 8
Question 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 is offline   Reply With Quote
Old 11th April 2016, 23:52   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,926
Variables work just fine. Your FileExists checks however should specify the full path!

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 13th April 2016, 02:07   #3
ajrjaneway
Junior Member
 
Join Date: Feb 2016
Posts: 8
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 is offline   Reply With Quote
Old 13th April 2016, 10:40   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Does $R1 have a trailing backslash?

Stu
Afrow UK is offline   Reply With Quote
Old 14th April 2016, 00:38   #5
ajrjaneway
Junior Member
 
Join Date: Feb 2016
Posts: 8
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.
ajrjaneway is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump