Author |
Topic: MKDIR error? (Read 462 times) |
|
mavison
New Member
member is offline


Posts: 27
|
 |
Re: MKDIR error?
« Reply #1 on: May 1st, 2017, 11:46am » |
|
To add to my post: It seems on MacOS I do get the same 254 error.
But on the Mac an OPENIN(dir$+"\NUL") always returns zero, even when the directory exists. That was the previous method I tried ... which did not work!
If 254 is correct and consistent then I can use that.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: MKDIR error?
« Reply #2 on: May 1st, 2017, 11:57am » |
|
on May 1st, 2017, 11:19am, mavison wrote:| The help for the MKDIR command says "If a directory with that name already exists, the File exists error will result." which is ERR 196. However, I seem to get ERR=254 Bad Command. |
|
The Help documentation for BB4W doesn't always apply in detail to BBCSDL; sometimes differences in the underlying Operating System make that inevitable.
Quote:| Will I get ERR=254 on both platforms? |
|
Ideally you should not rely on the error code, and nor should you rely on being able to tell the difference between a 'directory already exists' and some other reason for an error, because the underlying OS may not reliably report that information.
The safest thing to do is to wrap the MKDIR in a SEH (Structured Exception Handling) clause and treat all errors the same way. If you just want to ignore an error do this:
Code: ON ERROR LOCAL IF FALSE THEN OSCLI "mkdir ......." ENDIF : RESTORE ERROR Richard.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: MKDIR error?
« Reply #3 on: May 1st, 2017, 12:55pm » |
|
on May 1st, 2017, 11:46am, mavison wrote:| But on the Mac an OPENIN(dir$+"\NUL") always returns zero, even when the directory exists. |
|
Not only is the "NUL" filename an OS-specific feature, "\" isn't even a directory delimiter on a Mac!
Anyway, testing for the existence of a directory that way, even on Windows, is fundamentally flawed because it only tells you whether the directory existed at that instant. A few microseconds later things may be different: if the test told you the directory existed it may no longer do so, and if it told you it didn't now it might!
Some people think that trapping errors and allowing them to happen is poor programming practice, but on a pre-emptive multi-tasking system it is actually the best method.
Quote:If 254 is correct and consistent then I can use that. |
|
No, as I said, I cannot guarantee that. Treat all errors resulting from MKDIR the same, that way you won't need to care about the error code. Use SEH to confine the error trapping only to that command, as I showed.
I would want to be very cautious about relying on any error code other than those generated by the core BBC BASIC interpreter.
Richard.
|
|
Logged
|
|
|
|
mavison
New Member
member is offline


Posts: 27
|
 |
Re: MKDIR error?
« Reply #4 on: May 1st, 2017, 3:50pm » |
|
Quote:The Help documentation for BB4W doesn't always apply in detail to BBCSDL; sometimes differences in the underlying Operating System make that inevitable. |
|
I thought that might be the case. I am now using... Code:DEF PROCmkdir(dir$) :REM Create directory if does not existON ERROR LOCAL :IF ERR=254 THEN ENDPROC ELSE RESTORE ERROR :ERROR ERR,REPORT$+" at "+STR$ERLOSCLI("mkdir """+dir$+"""")ENDPROC which is has the same effect as your suggestion, but reports any other errors, and seems to work on both Windows and Mac (unlike the open /NULL). I note your concerns about using 254.
Thanks for your reply Richard.
Martin
|
| « Last Edit: May 1st, 2017, 3:53pm by mavison » |
Logged
|
|
|
|
|