More robust directory checking