There is no completely safe way to do this.
Your best bet will be to scan through all the files, check that you are allowed to delete them. Only if the scan succeeds do you then go through and do the actual deletion.
The catch is if something becomes locked after your scan but before you delete it then the deletion will still fail on that file.
The only alternative would be to keep a copy of all the files (i.e. move them to the recycle bin, store them in a zip, etc) until all the deletions have succeeded and only then empty the bin/delete the zip - if not restore.
But even then something could happen to block the restore.
Really you will have edge cases here, what you need to do is identify what they are and decide what the desired behaviour is in each case.