SpecialFolder mysteries

  1. 11 months ago

    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"

    "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.

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

  2. Julian S

    11 Apr 2018 Pre-Release Testers, Xojo Pro UK
    Edited 11 months ago


    On macOS, use SpecialFolder.ApplicationData to save your own files or directly call CFPreferences to save preferences files here.

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

  3. Emile S

    11 Apr 2018 Europe (France, Strasbourg)

    @Owen T I am using High Sierra.

    Surprise :(

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

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

  4. 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
    Catch e As IOException
          // handle
        End Try
  5. Dave S

    11 Apr 2018 San Diego, California USA

    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

  6. Derk J

    11 Apr 2018 Pre-Release Testers, Xojo Pro

    Shouldn’t it be:

    Stream = TextOutputstream.Create(f)
    Stream.Write “something”
    Catch e As IOException
    // Can’t write to file
    End Try
  7. 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.

  8. Paul M

    12 Apr 2018 Pre-Release Testers, Xojo Pro Answer

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

  9. Jared F

    12 Apr 2018 Pre-Release Testers, Xojo Pro Milwaukee, WI
    Edited 11 months ago

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

    The file was created successfully at this location:

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

  10. shao s

    13 Apr 2018 Pre-Release Testers Sudbury, Ontario, Canada

    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..

  11. Julia T

    13 Apr 2018 Sandy Hook, Connecticut

    @Owen T I can't find it in the Preferences folder.

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

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

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

  13. That simple, just hidden by the OS?

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

or Sign Up to reply!