fix checking for a file before try to open it