Archive: CreateDirectory does not set error flag?


CreateDirectory does not set error flag?
NSIS version I am using is the latest official release -- NSIS 2.06

Here are the two code samples. First one does not work, so I had to revert to the second one, which does what I want. By not working I mean that it obviously does not create the directory (which has an illegal character '?'), but also it does not display the message box, as it should.

1)
...
StrCpy $TMP_DIR "C:\lalala?"
ClearErrors
CreateDirectory "$TMP_DIR"
IfErrors 0 +3
MessageBox MB_OK "Cannot create directory '$TMP_DIR'"
Abort
...

2)
...
StrCpy $TMP_DIR "C:\lalala?"
ClearErrors
CreateDirectory "$TMP_DIR"
IfFileExists "$TMP_DIR\*.*" +3
MessageBox MB_OK "Cannot create directory '$TMP_DIR'"
Abort
...


Another relevant matter. Are the calls 'IfErrors' and 'GetErrorLevels' related? Would it be correct to say that 'IfErrors' checks whether there is any error at all, whereas 'GetErrorLevel $var' shows the actual error code value?


Sorry! My previous message is slightly misleading... In fact, I know what the problem is :-). Illegal characters for the dir/file name seem to simply get ignored! So when I tried to create a folder "lalala?", it actually translated it as "lalala", ignoring the '?'.

Another interesting thing totally relevant to the previous paragraph. If you put an illegal character in the path input box on the directory page, this character simply gets ignored!

Isn't all this a bit improper :-)? I think it would be much better for the script writer to handle such an error rather than implement some questionable :-) default behaviour...


I think it would be a very bad idea for it not to be automatic.
We'd have to parse all our CreateDirectory, SetOutPath etc strings for invalid characters, and apart from adding to the overhead it'd increase the script size as well.

-Stu


BTW this happens not only with ? and * (*.ns?), but with : as well.


You can't have these in file names:
\ / : * ? " < > |

-Stu


GetErrorLevel is not realted to IfErrors. See section 2 of appendix D.


AfrowUK, so let's say you are creating a directory in a certain file system via a UI or a command line. Would you like it if instead of telling you that the directory with the name you specified is invalid, it would actually create a directory with a different name from what you intended, chopping some characters it does not like and so on? This does not sound very attractive to me personally. I am just trying to reason...