FolderItem and file remove problem

Hi,
I have an IOException error code n° 1 (“Cannot delete the file because you do not have the necessary permission”) but with an ‘OpenFileDialog.ShowModal’, it’ works well !
I don’t think it’s a permission issue but more of the FolderItem syntax. What do you think ?

Var f As New FolderItem("", FolderItem.PathModes.Native)
//test too with 'Var f As New FolderItem'
f = SpecialFolder.ApplicationData.Child("com.apple.sharedfilelist").Child("com.apple.LSSharedFileList.RecentApplications.sfl2")
if f<> nil and f.Exists then
  Try
    f.Remove <-----------  IOException error!
  Catch error As IOException
    If error.ErrorNumber <> 0 Then
      MessageBox(error.Message)
    End If
  End Try

Works well with:

Var dlg As OpenFileDialog
dlg = New OpenFileDialog
f = dlg.ShowModal

Thanks

This 100% a permission issue you likely need to resolve using declares or MBS plugins.

Sorry but I don’t agree. The file can easily be deleted via Finder and have it with an OpenFileDialog box, without problem.

The Finder has all the permissions it needs. You app not. Trust me… it’s a permission issue and you need to ask macOS permission to tamper with files. That’s how it works with the latest macOS versions.

1 Like

If your app is not sandboxed, you could try to use Applescript to delete the files. But that is no guarantee either.

Its the same reason why iterating through the folders children didnt work in your other post.
The mac will only allow you to do some things if you explicitly ask the user to make the choice (openFolder dialog), but not if you just ‘do it behind the scenes’

Alright I understand. But I continue to look for the solution (there is always a solution), even if I understand that it is not here that I will find it…
“This is the same reason iterating through the child folders didn’t work in your other post.”
No, it worked perfectly when I found the right FolderItem syntax (see my last post for the solution)!
Thanks.

I’m afraid you’re right!