SpecialFolder mysteries

I have a problem with SpecialFolder
this code:

dim f As FolderItem
dim stream as textOutputStream
f = SpecialFolder.Preferences.child("XojoTestFile")
stream = f.CreateTextFile
stream.writeLine "File test"
stream.close

“works” because I can read it with stream.readLine - but I can’t find it in the Preferences folder. So where is it? What is the path to see where it is saved?
I am using High Sierra.

https://documentation.xojo.com/index.php/SpecialFolder

[quote]/Users/UserName/Library/Preferences
On macOS, use SpecialFolder.ApplicationData to save your own files or directly call CFPreferences to save preferences files here.[/quote]

Also, try running the Xojo Example, under the File>New>Examples>Files>SpecialFolderPaths, this will list all the locations of special folder end points.

Surprise :frowning:

That said, you do not use Try … End Try. Read the docs.

There: http://documentation.xojo.com/index.php/TextoutputStream

I think, I see:
When reading a file, then:

If f <> Nil Then If f.exists Then
Like I’ve used before, or at the other hand, had added to the code very rigorously now.
From the TextOutputStream linked above, it seems I would need to add the Try statement when attempting to save a newly created file then?

Dim f As FolderItem = Documents.Child("Sample.txt") If f <> Nil Then Try Catch e As IOException // handle End Try

NIL indicates the folderobject is not valid (either never been assigned, or has a path name that cannot legally exist)
Not Exists indicates the folderobject IS valid, but the named file is not located

So for a “newly created” file, NIL means you will fail if you attempt to create it
Exists can be used to check if you will over-write a previous file

Shouldn’t it be:


Try
Stream = TextOutputstream.Create(f)

Stream.Write “something”
Stream.Close

Catch e As IOException
// Can’t write to file

End Try

I don’t understand why the last 4 posts are in the conversation I started. And nobody has answered the question I posed: where is the file I created? It is not in the Preferences folder.

Try putting a breakpoint on the line after you assign f, and see what the debugger shows as the path for f.

I just copy pasted your code and ran it in the debugger on High Sierra.

The file was created successfully at this location:
/Users/tk86081/Library/Preferences/XojoTestFile

But yes, you should add a breakpoint to view the properties of your FolderItem variable.

On macOS, writing directly to the Preferences folder is frowned upon by Apple… If you want your preferences file to end up there, you need to use CF/NSPreferences, or write your code to save the file to the Application Support folder…

Are you looking in the right Preferences folder? There are two: one in /Library and one in /Library.

As others have suggested, breakpoint after you’ve assigned a value to f and inspect f’s path properties.

Thanks to everyone. Problem solved - my users Library was not showing, but have now found it (!) and my file was safely there.

That simple, just hidden by the OS?

On the Mac, the Goto menu item with Option key down enables the Library.
:slight_smile: