So, I am opening a text file that surely exists and can be read by other apps (e.g. in BBEdit and with the “cat” shell cmd), but Xojo 2016r3 gives me an IOException with ErrorNumber 2 and an empty Message and Reason. Also, when looking at the FolderItem’s properties in the debugger, I see that Exists and IsReadable are true and LastErrorCode is 0. Nothing indicates any potential problem.
No, I am not, But regardless, it should be readable. I open it without write permission, after all. And if other apps can open it that way, then it means it’s not exclusively locked, and therefore Xojo should be able to read it, too.
Well, does Xojo do that? It should not. At least not without giving me the option. We’re not even sure that’s the problem here. You add more theories - but do you actually know that’s what Xojo does?
Pretty sure error 2 means ‘no such file or directory’
Is the thing you are trying to open an alias?
You say the file is a text file, but you are opening in binary mode rather than textinputstream for some reason.
I seem to recall that other languages use exclusive for binary mode by default.
Binarystream.open has a locking preference parameter
I am glad they reduced the font size a bit. I couldnt believe it when I saw the first version during the Sierra beta phase. I mean, sure, programmers tend to sit much too long in front of their computers, but are their eyes that bad in general?
I usually use Xcodes docs now. Faster information, less design.
Jeff, it’s a plain text file, and opening a text file as a binary file is definitely not the issue here. Also, as I already wrote, I’m opening it read-only, just like you suggested. Now, how do I figure out what the value 2 means? Clicking on every of those 100s of constants is not a solution. Maybe I should quickly write a web crawler for that Apple web page…
To get the Error message of the listed no. use “strerror” (see “man strerror” in Terminal).
Quick and dirty I use an Xcode (8) playground
let s2 = NSString(cString: strerror(2), encoding: String.Encoding.utf8.rawValue)
let s13 = NSString(cString: strerror(13), encoding: String.Encoding.utf8.rawValue)
which gives “No such file or directory” for Error 2 and in my test “Permission denied” for error 13.
Now you can check for the real error reaon in the system call.
Youre right.
I can’t help you with that , I think that page is poor too.
Mmm… you said [quote]I open it without write permission, after all.[/quote]
To me, that didnt say explicitly ‘I opened it read-only’.
It sounded like it could just be an assumption based on NOT specifically asking for write permission.
Everyone always says ‘show us your code’
So Im sure its fine, and I know you’re experienced, but :
What does the opening line of code actually say?
And what is the nativepath of the folderitem you are using , at the point that it you try to open it?
That’s one reason I prefer OSX and Xojo over Linux and digging thru open source C code - Too many cmdline tools that I can’t manage to remember. Even DTrace, as great as it can be, requires me to spend hours on reading up on it again every time before I can use it for a small task.
Well … That assumes that the error codes we get from Xojo’s file functions are using those codes. AFAIK, strerror returns POSIX error codes, whereas Xojo uses MacOS level function calls and therefore gets OSError codes, which are of a different kind.
The issue here is that a single integer is not enough to know how to interpret an error code on OS X and implementing FolderItem can’t be done at one single API level.