Skip to content
⌘ NSIS Forum Archive

empty directory

8 posts

aviadlich#

empty directory

I am also new with NSIS
i am trying to do the following:
After the user picked the installation directory i want to warn (message box) him in case the directory is not empty and go back to the directory page if he wishes to.
I am using the

!insertmacro MUI_PAGE_DIRECTORY
for the directory page chooser.
How do i do it?
kichik#
The directory page won't let the user input an empty directory as it's invalid. Just try and see.

Please don't add your question to another thread unless it concerns the exact same topic.
aviadlich#
I am not trying to insert an empty string
i want to check that the user didnt pick a directory tat exists and has data in it.
kichik#
Oh, right. Of course that's what you'd want... 🙂 Check if the directory has any files in it in the leave function of the page. To check that, use isEmptyDir.
aviadlich#
Thanks for the quick reply
And how do i get to the leave function of the page
I couldnt find it using the MUI_PAGE_DIRECTORY
timberman#
Originally posted by kichik
Oh, right. Of course that's what you'd want... 🙂 Check if the directory has any files in it in the leave function of the page. To check that, use isEmptyDir.
There is also the ${DirState} macro from FileFunc.nsh

example:
!include "FileFunc.nsh" ;required for target dir validation
    !insertmacro "DirState"
.
.
.
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "ValidateInstallationDir"
!insertmacro MUI_PAGE_DIRECTORY
.
.
.
.
Function ValidateInstallationDir
    ;make sure $INSTDIR path is either empty or does not exist.
    Push $0
    ${DirState} "$INSTDIR" $0
    ${If} $0 == 1   ;folder is full.  (other values: 0: empty, -1: not found)
        ;refuse selection
        MessageBox MB_OK|MB_ICONSTOP "$(msgDirectoryNotEmpty)"
        Abort
    ${EndIf}
    Pop $0
FunctionEnd