Fix exception getting directory from invalid URI