Removing an App?

I’m having problems removing an app from a folder. I built a method to recursively remove he contents of the app folder so that I can then remove the app. The app is another app I built for updating the main app to a new version. I need to delete the updater app at a certain point but it won’t work. However, no matter how I do it, the program always crashes when trying to remove the app folder, saying that the directory is not empty. Is there a better way to remove an app? TIA

Well, it would help if we saw your code and the crash log. Also important is the location of the app. If the app is in the app folder then you need to use AuthorizationMBS with a simple shellscript:

#!/bin/sh
if [ -d “$1” ]; then
rm -rf “$1”
fi

You should be catching your exceptions so that it doesn’t crash, and using API 2 methods so that you get exceptions when something goes wrong. Odds are a file is still in use or you don’t have permission. If the file is in use, I bet you need to wait for the updater to finish before trying to delete it. If you don’t have permission, something like what Beatrix suggested would be needed.

Your function might look something like

Function DeepDelete(Extends Target As FolderItem)
  If Target.IsFolder Then
    For Each Child As FolderItem In Target.Children(False)
      Child.DeepDelete
    Next
  End If
  Target.Remove
End Function

Then use it like:

Try
  UpdaterApp.DeepDelete
Catch Err As IOException
  // Do something to handle the error
End Try

I would not recommend putting the exception handling inside the method so that you can control its behavior on a case-by-case basis.

Anyway, Err will have more details about what went wrong, and you can stop the app from crashing.