Set shell current working directory.

def set_cwd(self, dirname):
        """Set shell current working directory."""
        # Replace single for double backslashes on Windows
        if os.name == 'nt':
            dirname = dirname.replace(u"\\", u"\\\\")

        if not self.external_kernel:
            code = u"get_ipython().kernel.set_cwd(u'''{}''')".format(dirname)
            if self._reading:
                self.kernel_client.input(u'!' + code)
            else:
                self.silent_execute(code)
            self._cwd = dirname