check permissions before changing directory