Hi, I'm extremely new to NSIS but I've been picking it up pretty quickly. I'm trying to write a function that checks if a file exists, and if it does, define it, and then later install it. And if the file doesn't exist then just don't define it. However, every time I run the program, it supposedly finds the file even if it doesn't exist. I've deleted the files multiple times but it still creates them, and even installs them. Does any one know where NSIS could be finding these files? Any help is appreciated!
Code:
!include LogicLib.nsh
!define SOURCEPATH1 "C:\Program Files\PODS\Config Files"
IfFileExists "${SOURCEPATH1}\B1EZ1013_MAP085e_T.xml" 'secondDoesExist' 'secondNotExist' ;checks if file exists
secondDoesExist:
!define XMLFILENAME2 "B1EZ1013_MAP085e_T.xml" ;name the file
!define XMLNAME2 "B1EZ1013_MAP085" ;name the file
IfFileExists "${SOURCEPATH1}\B1EZ1009_MAP069Be_T.xml" 'thirdDoesExist' 'thirdNotExist' ;checks if file exists
thirdDoesExist:
!define XMLFILENAME3 "B1EZ1009_MAP069Be_T.xml" ;name the file
!define XMLNAME3 "B1EZ1009_MAP069B" ;name the file
secondNotExist:
!ifdef XMLFILENAME2
DetailPrint "Test. 2nd File is found and defined."
!endif
thirdNotExist:
!ifdef XMLFILENAME3
DetailPrint "Test. 3rd File is found and defined."
!endif
If File Exist Finding Files That Shouldn't Exist
5 posts
You are mixing compile-time and run-time concepts!
All instructions starting with ! are compile-time based and happen on the computer you are compiling on. You can use !if /fileexists with !define.
IfFileExists must be paired with $variables and they are usable on the end-users system.
All instructions starting with ! are compile-time based and happen on the computer you are compiling on. You can use !if /fileexists with !define.
IfFileExists must be paired with $variables and they are usable on the end-users system.
Ok, so just so I'm understanding (hopefully), the files are always being found because I'm using a runtime syntax to check if they exist, but defining them at compile time. So when I compile, the files will automatically be defined, because it doesn't check if they exist until runtime. This would actually make sense because my code later on just checks that those files are defined as those names, and then installs them if they are. And if this is the case, the solution would be something like:
!if /fileexists "${SOURCEPATH1}\B1EZ1013_MAP085e_T.xml" 'secondDoesExist'
(not sure on that syntax, I see that !if can compare two values or use a non zero, not sure if I can still use gotos.)
'secondNotExist' ;checks if file exists
secondDoesExist:
!define XMLFILENAME2 "B1EZ1013_MAP085e_T.xml" ;name the file
!define XMLNAME2 "B1EZ1013_MAP085" ;name the file
If this is sounding wrong I apologize, I'm only a few days in and trying to learn as best as I can. This is my first language like this and it's pretty intimidating. Again, thanks in advance for your time and help.
!if /fileexists "${SOURCEPATH1}\B1EZ1013_MAP085e_T.xml" 'secondDoesExist'
(not sure on that syntax, I see that !if can compare two values or use a non zero, not sure if I can still use gotos.)
'secondNotExist' ;checks if file exists
secondDoesExist:
!define XMLFILENAME2 "B1EZ1013_MAP085e_T.xml" ;name the file
!define XMLNAME2 "B1EZ1013_MAP085" ;name the file
If this is sounding wrong I apologize, I'm only a few days in and trying to learn as best as I can. This is my first language like this and it's pretty intimidating. Again, thanks in advance for your time and help.
No you cannot use goto with !if.
!if xMaybe you should try reading the help file again, it should contain some small code snippets etc.
!y
!else
!z
!endif
I was able to find some examples online after knowing what I was looking for. Thanks for the help!