Write/Read from app folder

Hi

I can’t find a way to write/read files on my apps folder

I tried this

Var f as folderitem
f = app.executablefile.child(“myfile.txt”)
but it doesnt work.

I don’t undersrtand the logic since "specialfolder.desktop.child(“myfile.txt”) works fine…

thanks

I looked into the documentation but didn’t found what I was looking for. I my memory serves me well, a user is not allowed to access the apps folder, only the OS is able to.

Is this on MacOS or WIndows ?

Not allowed on either.

Use something like
f = specialfolder.documents.child("myfile.txt")

and preferably

f = specialfolder.applicationdata.child(“myapp").child("myfile.txt")

having made the myapp folder on first run.

Are you debugging?
Are you copying (build step) “myfile.txt” next to your executable?

You may be able to read (at least with an older version of the OS) but not write.

at windows you can read/write at all folders but you have to set the permissions.
use also try catch
for folderitem use .exists method.
put any user data in user folder not global.
with build step you can add template files beside your exe or sub folders to read within your app.

I was able to test and it does work. It helps when you can provide more information like ‘what doesn’t work’.

Here I have the test project with “myfile.txt”
image

As I’m using a Mac, I added the build step copyfiles and dragged the file “myfile.txt” to it:

then I put the original code in a button:
image

Run:
image

Shouldn’t it be app.executablefile.PARENT.Child("myfile.txt")?

2 Likes

Even with the correct path, writing inside the app folder must be avoided for at least two reasons:
1: it’ll break the app’s signature, so the app won’t launch subsequently.
2: non-admin users aren’t allowed to write to them (permissions).

Is that not the same as:

f = SpecialFolder.Applications.Child("myfile.txt")

if the “myfile.txt” is copied to the OS applications/program files folder, no?

In MacOS, the executable would be /Applications/MyApp.app/Contents/MacOS/MyApp (if the app is stored in /Applications, of course). That’s not the enclosing bundle, but the true executable.

1 Like

Thanks, so for this case “myfile.txt” should be inside /MyApp.app/Contents/ for the app.executablefile.PARENT.Child("myfile.txt") code to work, right?

I’m sorry I’m confused with OP’s mention of “on my apps folder” and the code posted.

app.executablefile returns this: …/TheApp.app/Contents/MacOS/TheApp
So app.executablefile.parent is …/TheApp.app/Contents/MacOS/
Thus app.executablefile.parent.Child(“myfile.txt”) refers to …/TheApp.app/Contents/MacOS/myfile.txt

The fact that we have app.executablefile and New FolderItem (and yet other functions, for wither the inner executable or the bundle) are confusing. I always check whether I’m knowing right, in the documentation, before using one of them.

I’ve alway copied the file into Resources. You can then access it using:

Var myFile as FolderItem = SpecialFolder.Resource( "myfile.txt" )

You dont even need to do that…

But again, you can only READ from the app’s location, or the resources folder.
If you want to WRITE to this data, it must be in documents or application data folders, for any app you ship.