>Have you tried using FILE() to check for the file?
Yes, this is a simplified version of the code. In the code here, we have IF FILE()... before ERASE. However, it is so close that even if IF FILE()... succeeds, by the time it reaches the ERASE line, it's too late.