This can have a race condition, you should try to unlink no matter what, and catch the exception that says "hey, this is not a file, you can't do that".