How do you Overwrite an Existing File in Shared Scope (Documents)?

I'm using the File component to copy a file named a.csv to the Shared scope in the Documents folder.
The first time it copies correctly as a.csv.

But when I try to copy the file again, it doesn't overwrite the existing file — instead, it creates a new file named a.csv (1).
I tried using the File.Delete block before copying, but it doesn’t actually delete the file from the Documents folder.

My goal is to overwrite or replace the existing a.csv file in the Documents folder, not create duplicates like a.csv (1).
Is there a proper way to delete files in Shared scope?

What’s the correct method to ensure overwrite works?   

Any suggestions or example blocks would be very helpful!

Use SAF

This will allow you to delete the existing and write the new one, regardless of whether your app owns the file or not.

do I need to prompt the user to select the file via SAF every time I want to delete or overwrite it? Or is there a way to programmatically access and manage that specific file (using its URI or other means) after the initial selection?

My goal is to reliably overwrite or replace the file in the Documents folder without user interaction on every operation.

i mean, In the File.Delete block I can simply provide the file name to delete it—is it possible with SAF ?

You can try constructing the uriString for the file and see if that works.

Runtime Error : authority

another
Runtime Error

Permission Denial: writing com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/primary%3ADocuments%2Fmath.csv from pid=16564, uid=10415 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()

If the CSV file is created (copied) by your app in/to /Documents you can of course delete it with the File component without any storage permissions on Android 11+. If the CSV file is already created by the Companion app, you cannot delete/overwrite it with the compiled app, because this is another app. So delete it before testing with Companion and APK.

Example:

Thank You.... :slightly_smiling_face:

But it asking permission for Music and audio and Photos and videos

Show your relevant blocks.

Hmm, what does this have to do with music, audio, photos & videos?
Post a screenshot of this issue.

These are permissions for the Companion app. You only need to grant them once. Build the APK and try...

when i click save button

And again, which audio (media) files does your app access? Show your relevant blocks.

i am sending aia file to you

I don't have time to work through your app. Create a simple test app that demonstrates the problem. And explain the purpose of your app.

test.aia (5.0 KB)

At first, the file is saved without any issue, but after a few clicks, it shows an error: "Cannot delete file at Documents/math.csv." As a result, new files are created with names like math.csv (1), math.csv (2), and so on. and also asking for permission.