Archive: empty directory


validate directory is empty
  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?

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.


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.


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.


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


!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY

Stu


Thanks


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:

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
>