Search code examples
windowsinstallationnsiserror-checkingcreate-directory

Creating an empty directory (NSIS)


How can I do it by NSIS 2.46?

I know this is probably a dumb question, but how the heck do I create an empty directory and check for errors?

I do so:

ClearErrors
CreateDirectory $R1
${If} ${Errors} 
  DetailPrint "failed"
  MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Can not create folder $R1"
  Abort
${Else}
  DetailPrint "done"
${EndIf}

if the variable $R1 is

  • "c:\test" - done
  • "c:\con" - failed ("con" - reserved on Windows)
  • "qwer:\test2" - done
  • "qwer\test3" - done (without ":")

why "test2" and "test3" without errors?

UPDATE: How to make that it was an error?


Solution

  • I decided:

    ClearErrors
    CreateDirectory $R1
    ${If} ${Errors} 
    ${OrIfNot} ${FileExists} "$R1\*.*"
      DetailPrint "failed"
      MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Can not create folder $R1"
      Abort
    ${Else}
      DetailPrint "done"
    ${EndIf}
    

    have more ideas?