Skip to content
⌘ NSIS Forum Archive

How to require a non-existent installation directory?

6 posts

envoy510#

How to require a non-existent installation directory?

Also, I'm not using MUI. I just want to require that the installation directory does not exist.

I've googled, searched this forum and the closest I came was this on stackoverflow.

Any ideas? Thanks.
aerDNA#
You didn't bother explaining too precisely what you're trying to achieve in practice, but maybe something like this?

InstallDir $PROGRAMFILES\MyAppDir
Page directory "" "" CheckInstDir
Function CheckInstDir
IfFileExists "$INSTDIR\*.*" 0 +3
MessageBox MB_OK|MB_ICONSTOP "$INSTDIR already exists, select a different dir."
Abort
FunctionEnd 
Error msg will be displayed if user selects an existing path that ends with \MyAppDir.
envoy510#
Originally Posted by Anders View Post
MUI is not required, just use Page Directory "" "" MyLeaveFunction...
Indeed that does work. Thank you very much. I'll point this out on SO.
envoy510#
Originally Posted by aerDNA View Post
You didn't bother explaining too precisely what you're trying to achieve in practice, but maybe something like this?

InstallDir $PROGRAMFILES\MyAppDir
Page directory "" "" CheckInstDir
Function CheckInstDir
IfFileExists "$INSTDIR\*.*" 0 +3
MessageBox MB_OK|MB_ICONSTOP "$INSTDIR already exists, select a different dir."
Abort
FunctionEnd 
Error msg will be displayed if user selects an existing path that ends with \MyAppDir.
That's exactly what I did, though I left off the \*.* on the IfFileExists. Is there a reason to use your version? I've tested my version and it appears to work as I want (calls Abort if the directory exists, doesn't if it doesn't).
aerDNA#
No, it's just a habit. It would matter if you needed to distinguish a file from a dir but in this case you don't.
Edit: there's the possibility that an actual file exists with same path but in that case the 'Install' button will be disabled anyway.