Delete folderitem that's an APP or DMG?

I’ve encountered an issue deleting an folderitem that points to an APP or DMG indicating that the folder is not empty? I’m assuming that is because APPs and DMGs are actually packages (with folders in them)?

What is the recommended way to delete these?

How do you delete the folderitem? From where do you delete the folderitem?

.app bundles are indeed folders and need to be treated that way.

.dmg is not though… but they can be locked if they are mounted. You’ll need to make sure you unmount the associated volume before trying to delete the file.

Beatrix

So this is an application that builds the DMG and uploads to our website; however, I have modified it to call AppWrapper to do the code sign and notarization, then our app will delete the old DMG and copy the one generated by AppWrapper to the location where our app can find it to upload to our website.

I couldn’t get the folderitem.remove to work without generating an error, so I decided to use a shell command and that’s working.

Consistently get an error when trying to delete the DMG. I decided to use a shell command to delete it and that’s working.

rm -R {folderitem.nativepath}

Deleting folders requires them to be empty first. So a recursive function to empty it first will be necessary. That’s what the “-r” option does for the rm command.

And DMGs can sometimes be bundles, such as if you use the sparsebundle format. The format is often better for backups because only modified chunks need to be copied, rather than the whole image. But since they are folders, they aren’t good for app distribution or sharing with non-Apple devices.

1 Like