Checking for the existence of a directory should have been checking for the nonexistence of the directory.