Archive: FindNext Does Not Work - Why?


FindNext Does Not Work - Why?
Hello,

The "findNext" function does not seem to work. It's as if every time it gets executed the Uninstaller just stops executing.

Below is the code:
FindFirst $0 $1 $INSTDIR\server\webapps\*.xml
FindContextsLoop:
StrCmp $1 "" FindContextsLoopDone
${UnStrRep} $R0 "$1" ".xml" ""
MessageBox MB_OK "About to Delete Virtual Directory: $R0"
!insertmacro DELETE_VIRTUAL_DIRECTORY $R0
MessageBox MB_OK "Just deleted Virtual Directory: $R0"
MessageBox MB_OK "Dollar Zero = $0"
MessageBox MB_OK "Dollar One = $1"
FindNext $0 $1
IfErrors 0 FindContextsLoop
FindContextsLoopDone:
FindClose $0

Please help me.

Thanks!


You must clear the error flag before you use the instruction you wish to test for using IfErrors. The error flag might be set by anything executed before FindNext. You'll therefore test everything above it, not only FindNext itself.

ClearErrors
FindNext $0 $1
IfErrors 0 FindContextsLoop

Still Not Working
I tried the above in inside my UnInstaller code. Adding the "ClearErrors" instruction before executing "FindNext" still did not cause the program to work. When the UnIninstaller tries to execute "FindNext" it simply stops executing.

Below is the code:
StrCpy $0 ""
StrCpy $1 ""
StrCpy $R0 ""
FindFirst $0 $1 $INSTDIR\server\webapps\*.xml
FindContextsLoop:
StrCmp $1 "" FindContextsLoopDone
${UnStrRep} $R0 "$1" ".xml" ""
MessageBox MB_OK "About to Delete Virtual Directory: $R0"
!insertmacro DELETE_VIRTUAL_DIRECTORY $R0
MessageBox MB_OK "Just deleted Virtual Directory: $R0"
MessageBox MB_OK "Dollar Zero = $0"
MessageBox MB_OK "Dollar One = $1"
ClearErrors
MessageBox MB_OK "Just completed ClearErrors instruction."
MessageBox MB_OK "About to execute FindNext instruction."
FindNext $0 $1
MessageBox MB_OK "Just completed FindNext instruction."
IfErrors 0 FindContextsLoop
FindContextsLoopDone:
FindClose $0

Please help me.

Thanks.


What exactly do you mean by "stops executing"? Does no message box show up after "About to execute FindNext instruction"? What does happen, if it doesn't show?


Maybe some problem with handle, try to comment out:

# ${UnStrRep} $R0 "$1" ".xml" ""
# !insertmacro DELETE_VIRTUAL_DIRECTORY $R0

>What exactly do you mean by "stops executing"? Does no >message box show up after "About to execute FindNext >instruction"? What does happen, if it doesn't show?

That's exactly what I mean. The next message box that should appear is the one stating "Just completed FindNext instruction." Then, the UnInstaller simply stops executing.

Any answers why?


I believe Instructor is right. DELETE_VIRTUAL_DIRECTORY must have changed $0 and/or $1.


Hi. I fixed the problem by not using $0 and $1. Instead I used global variables I defined myself.

Below is the code that works:
StrCpy $R0 ""
var /GLOBAL FileHandle
var /GLOBAL FileName
StrCpy $FileHandle ""
StrCpy $FileName ""
FindFirst $FileHandle $FileName $INSTDIR\server\webapps\*.xml
FindContextsLoop:
StrCmp $FileName "" FindContextsLoopDone
${UnStrRep} $R0 "$FileName" ".xml" ""
MessageBox MB_OK "About to Delete Virtual Directory: $R0"
!insertmacro DELETE_VIRTUAL_DIRECTORY $R0
MessageBox MB_OK "Just deleted Virtual Directory: $R0"
MessageBox MB_OK "FileHandle = $FileHandle"
MessageBox MB_OK "FileName = $FileName"
ClearErrors
MessageBox MB_OK "Just completed ClearErrors instruction."
MessageBox MB_OK "About to execute FindNext instruction."
FindNext $FileHandle $FileName
MessageBox MB_OK "Just completed FindNext instruction."
IfErrors 0 FindContextsLoop
FindContextsLoopDone:
FindClose $FileHandle

Thanks for your help.