TextOutputStream.Create (on a Folder) does not raise an IOExceptionError

The code below comes from SelectFolderDialog excepted the part in the f <> Nil block: the part to write to the selected folder.

Do not get me wrong: Xojo do exactly what I asked it to do: it write to the Folder, not inside the folder. I do that on purpose because I was hunting the IOExceptionError I get in a current project.

I was suspecting this kind of error (from me).

Code to replicate the issue:

[code] Dim dlg As New SelectFolderDialog
dlg.ActionButtonCaption = “Select”
dlg.Title = “Title Property”
dlg.PromptText = “Prompt Text”
dlg.InitialDirectory = SpecialFolder.Documents

Dim f As FolderItem
f = dlg.ShowModal
If f <> Nil Then
// Use the folderitem here

// Now try the impossible: write in the Folder reference
Dim TOS As TextOutputStream

TOS = TextOutputStream.Create(f)
TOS.WriteLine "This have to ring an error. Will this be the IOExceptionError I am searching ?"
TOS.Close

Else
// User cancelled
End If[/code]

The answer to my question is no.

Tested with Xojo 2016r1.1 and Xojo 2016r2 (+ 2015r1)
OS X 10.11.5

The Folder is destroyed and a text file appears instead (without the txt extension)
Do not do silly things Emile

Feedback: 44571 - TextOutputStream.Create does not raises an IOException

An example project is provided (one PushButton and the code above…).

I continued my quest to get voluntary the IOExceptionError and found it:

Same code, but TextInputStream is used: the run crash on TextInputStream.Open(f)
More complex code with both BinaryStream.Create(f) and BinaryStream.Open(f): the run crash on both lines.

I still do not found an answer to my main question: why did I get IOExceptionError in my project…
(I will investigate a little bit my code for TextInputStream.Open(f), BinaryStream.Create(f) and BinaryStream.Open(f), just in case I used them and place a check before these lines on the FolderItem: is it a Directory ?)

This may not be a bug. If the user specifically selects the folder and there is nothing in it, the OS may have permission to delete it. If on OS X, remember that bundles are folders, so it may not be able to tell the difference. It may be up to you as developer to use the right dialog.

You are right Greg, but even if I specifically choosed a folder (SelectFolderDialog), why can I do it ?

BTW: fortunately, I’ve created a folder for the test.

I was doing that on purpose in a search for a real problem I have in my current project.

Thank you for your answer.

The idea and what I found as reported here leads me to discover - apparently - what caused (more or less) the IOExpectionError in the project.

I do not know how that happened, but apparently, the file name was concatenated to the path where the file have to be saved (I checked csv, but I am quite sure the same reason apply to txt). Of course, a path that does not exists… leads to errors.

The Menu Handler ask the user to choose a folder and set a file name, then call a method with the FolderItem that does the save. I only commented the call to the method and copy that method / paste it after the line I just commented, run and the IOExpectionError goes away…

Nota: the test file I loaded always falled into IOExpectionError when I wanted to save it. Now it is allowed to be saved.

Conclusion: I am not sure that IOExpectionError is really squashed, but it seems so AND I do not know how (or/and why) it was removed.

I am a bit happy. I will be fully happy if the IOExpectionError never re-appears again.