check directory before cd