Make sure file exists before getting dirname() and basename() from it.