added logic to prevent error messeage when trying to delete a file.