Archive: IfFileExists - what am I doing wrong?


IfFileExists - what am I doing wrong?
Hi.

I'm working on an installer now, that has to take into account if a file is already installed.

If it finds that the file is already there, it's supposed to back up that file before it extracts the alternative file that is in the installer I am now making.

So for this I have tried to use IfFileExists.

But I must be doing something wrong, because it's not doing what I want it to do.

Here's the script snippet(names changed etc.):


Section "Install section nr. 2." Sec02
IfFileExists "$INSTDIR\EXAMPLE_DIRECTORY\examplefile1.bmp" 0 nofile1
CreateDirectory "$INSTDIR\EXAMPLE_DIRECTORY\BMP_Backup"
CopyFiles "$INSTDIR\EXAMPLE_DIRECTORY\examplefile1.bmp" "$INSTDIR\EXAMPLE_DIRECTORY\BMP_Backup\examplefile1.bmp"

SetOutPath "$INSTDIR\EXAMPLE_DIRECTORY"
File "examplefile2.bmp"

nofile1:
SetOutPath "$INSTDIR\EXAMPLE_DIRECTORY"
File "examplefile2.bmp"
SectionEnd



What happens in the script above, is that it doesn't seem to care about the 'IfFileExists' command - it does both of those actions like they were right after each other. The whole point of using IfFileExists is that I want it to jump to the next action if the file doesn't exist(because I don't have to make a backup then obviously), but it doesn't jump, it just continues and does both actions of the Section.

The weird thing is that it "partially" works:

If the original file exists, it does make a backup directory and puts the file in there, and if the file doesn't exist, it just extracts the new file.

So far so good.

But it also goes on to perform the second action no matter what.

I verified this because when I remove the first SetOutPath action, and the file already exists, it makes the backup, but the new file is still extracted, which means it must be continuing on to perform the second action as well(which it's supposed to skip).


I also tried to store the directory string in a variable, in case that was needed when using IfFileExists, like this:

StrCpy $0 "$INSTDIR\EXAMPLE_DIRECTORY\examplefile1.bmp"
IfFileExists $0 0 nofile1

But the same thing happens then.


The same problem then occurs in the uninstall section, since it then both removes the backup folder I made, and removes the file in the root folder, when it's supposed to do only one of those ations(copy from backup folder if the file was there, but just delete the new file if it wasn't there to begin with).


So how am I supposed to use it?

it does both of those actions like they were right after each other.
They are. The label doesn't mean "stop execution here", it means "I might want to jump here, remember this spot under this name".

you have to insert a goto:

SetOutPath "$INSTDIR\EXAMPLE_DIRECTORY"
File "examplefile2.bmp"
Goto End

nofile1:
SetOutPath "$INSTDIR\EXAMPLE_DIRECTORY"
File "examplefile2.bmp"
End:
SectionEnd

Woah, that was fast! :D

OK - I AM a newbie.

Thanks, I'll try that. :)