Archive: Is path writable?


Is path writable?
How do i check if a Directory i writable?
Im trying to make sure user don't choose wrong directory in
.onVerifyInstDir

Saw this function somewhere:

Function .onVerifyInstDir
ClearErrors
SetOutPath $INSTDIR

FileOpen $0 ${GUID_FILE} "w"
FileWriteByte $0 "0"
IfErrors notPossible possible

notPossible:
MessageBox MB_OK "Not able to write into this directory! Choose another one."
Abort
possible:
FileClose $0
Delete "$INSTDIR\${GUID_FILE}"


FunctionEnd


This function don't work well beacuse it will create directorys that don't exist if user enters own path.


If you do not want the user to enter a non-existant directory path, then...


Function .onVerifyInstDir
IfFileExists "$INSTDIR\*.*" +3
MessageBox MB_OK "Please enter a directory path that exists!"
Abort

ClearErrors

FileOpen $0 "$INSTDIR\${GUID_FILE}" "w"
FileWriteByte $0 "0"
IfErrors 0 possible
MessageBox MB_OK "Not able to write into this directory! Choose another one."
Abort
possible:
FileClose $0
Delete "$INSTDIR\${GUID_FILE}"

FunctionEnd


-Stu

But if they should be able to ?
I there not an easy way to check if a directory is writable.

The problem is that there are limited users (Not admin) that can't write to $PROGRAMFILES. So must detect if dir is valid or elese force to choose a new one. The program will install to a new dir ($PROGRAMFILES\AppName). Perhaps to check when Finsihed is pressed? Any Ideas anyone?


Ok this works.
Now the directory above "AppName" is checked if it exist
and if it's writable. This is ok. Also added this
function in a "!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "DirectoryLeave" Function " so user can't type wrong path.

Can I stop user from using EditBox?




InstallDir "$PROGRAMFILES\AppName"
...
...
;This function verifyes that output directory is writable
Function .onVerifyInstDir

IfFileExists "$INSTDIR\..\*.*" +3
MessageBox MB_OK "Please enter a directory path that exists!"
Abort

ClearErrors

FileOpen $0 "$INSTDIR\..\${GUID_FILE}" "w"
FileWriteByte $0 "0"
IfErrors notPossible possible

notPossible:
MessageBox MB_OK "Not able to write into this directory! Choose another one."
Abort
possible:
FileClose $0
Delete "$INSTDIR\..\${GUID_FILE}"


FunctionEnd

I'd simply put the original check in the leave function. This way, only when the user clicks next the directory will be created. If it's writable, you're good to go. Only the directory the user wants to create will be created because he already clicked next.