When all you have is a hammer, every problem looks like a nail.
You're trying to do something with code, that's not the code's job. Delete all this code and tackle the problem at the root: make sure your code runs with the appropriate permissions.
It's that simple.
-- My humble opinion
Deleting folders is a risky business
Indeed! If your running code doesn't have permission to wipe out your hard drive, you have some exceptions to deal with, i.e. you should wrap I/O calls in a try...catch
block.