SpecialFolder mysteries

  1. last week

    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.

    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

    Apr 11 Pre-Release Testers, Xojo Pro UK
    Edited last week

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

    /Users/UserName/Library/Preferences
    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

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

    Apr 11 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

    Apr 11 Pre-Release Testers, Xojo Pro

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

    Apr 12 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

    Apr 12 Pre-Release Testers, Xojo Pro Milwaukee, WI
    Edited last week

    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.

  10. 7 days ago

    shao s

    Apr 13 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. 6 days ago

    @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. 4 days ago

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

  13. 3 days ago

    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!