public function chdir($dir, $check = true)
    {
        if (!is_string($dir)) {
            throw new InvalidArgumentException("string", 0);
        }

        if ($check && !is_dir($dir)) {
            throw new Exception("No such directory $dir");
        }

        $this->cwd = $dir;

        return $this;
    }