verify if directory exists before changing to it