The Remove function will only delete an empty folder. But I have a folder with 100s of folders inside, many nested within other folders, and many folders with many files. Isn’t there a way to delete a folder with contents without iterating through every nested folder and file?
You got code to do that here:
If you can, the fastest way is to use a Shell with
rm -r /path/to/folder (or the Windows equivalent). Just be very careful to give it the right path.
@Bill Mounce Well, deleting is dangerous when you usually just need to “move to the trash”. That is why it is kept difficult.
Actually, moving to the trash is recoverable.
rm -r is not with regular means.
Technically it’s not difficult, there is OS API for removing items, that works on complex folder structures as well as single files (with one command), Xojo make it more difficult.
I will agree that moving the User’s data to the Trash is the most ideal situation, just make sure that the function is labelled as “Move to Trash” so the user is at least partially aware of what the action actually does.
For temporary files, just delete them, otherwise you can fill up the Trash and the user is unaware that it’s consuming their disk space.
For both options, it can be accomplished using declares or pluginesses.
Does the suggested code delete folders inside of folders that are inside of folders? I don’t think so, but I may not be reading the code properly. I am wanting to remove folders and files that were part of the install process, so I can’t run a shell command from the installer (ClickInstall)
I would recommend to just move to trash.
and see trachItem method in NSFileManagerMBS class.
The function DeleteEntireFolder deletes all the content, including subdirectories (folders inside folders).