GetFolderItem refresher

Banging my head…

I’m creating a new file, “Record_2”, in a directory “CalibrationRecords” that resides adjacent to the app. This works great on Linux (when you remove the leading “/”), but on the macOS I’m not having any luck.

When I write a binary file to this FolderItem I get a files named “/CalibrationRecords/Record_2” in my local directory. On Linux this works fine, in that it creates the file “Record_2” inside the existing directory “Calibration Records”.

I’ve tried a 1000 wrong things, but won’t paste them all here. Instead here’s the snippet I’m trying to use that’s bringing me no success on the macOS…

If TargetWin32 Then
’ n/a
ElseIf TargetMacOS Then
f = GetFolderItem("/CalibrationRecords/Record_2")
ElseIf TargetLinux Then
f = GetFolderItem(“CalibrationRecords/Record_2”)
End If

Thanks for any help.

thats most likely your problem. NOT where you should store local data… search this forum for the myriad of other topics discussing that exact issue.

and that not withstanding… look into CHILD function… GetFolder(“CalibrationRecords”).child(“Record_2”)

Thanks Dave! The syntax on “.child” was eluding me, and I didn’t want to create a Frankenstein path statement when all I needed was relative.

FWIW: I agree in general with the forum consensus on application data storage. Thanks again!

Well, since we’re refreshing: Now is the best time to forget GetFolderItem ever existed. If you can’t access the file with SepcialFolder.Temporary, SpecialFolder.ApplicationSupport, or an Open/Save dialog then you can’t get to the file inside the Apple sandbox, or when translocated.

In production, you cannot store files next to the app or get anywhere besides the two SpecialFolder locations I just mentioned without an Open/Save dialog with a macOS app. It may work on your local machine during testing, but as soon as you deliver to a customer or client you’re playing with fire (the Translocation and Quarantine systems.)

Check out the free open source TPSF module for help with getting to your own app’s special Application Support folder:

Then, you’d switch out your GetFolderItem above with something like this:

f = TPSF.AppSupport.Child("CalibrationRecords").Child("Record_2")

No need for any cross platform handling with the module :slight_smile:

One thing to note that sometimes gets missed by first timers with the module is that it does not do the existing / nil checking and will not create the folders for you. It simply provides the cross-platform access to the right locations.

In this specific case I’m lucky to be doing testing on my local machine, but deploying to a Linux appliance - so the macOS stuff will be stripped out when compiled and used on that other platform.

I do very much appreciate the heads-up regarding Apple’s sandboxing - and I’ll keep this handy as I’m sure it will prevent me from further unnecessary frustration :slight_smile: