check if directory exists, fixed issue #591