Repository: spyder-ide/spyder

Issue:
Can't change dir to network drive in console
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

ust installed spyder 4.0. this error is coming up when i access a folder or a file. 

### Traceback
```python-traceback
Exception in comms call set_cwd:
  File "C:\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 342, in _handle_remote_call
    buffer['call_kwargs'])
  File "C:\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    *call_args, **call_kwargs)
  File "C:\Anaconda3\lib\site-packages\spyder_kernels\console\kernel.py", line 352, in set_cwd
    os.chdir(dirname)
FileNotFoundError: [Errno 2] The specified path is invalid: '\\\\\\\\fs01\\\\users\\\\ora\\\\Python Scripts\\\\HS_Scanner'
WARNING:spyder.widgets.github.backend:Failed to send bug report on Github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
WARNING:spyder.widgets.github.backend:Failed to send bug report on Github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
```

## Versions

* Spyder version: 4.0.0rc2 
* Python version: 3.6.8
* Qt version: 5.11.2
* PyQt5 version: 5.11.3
* Operating System: Windows 10

### Dependencies

```
cloudpickle >=0.5.0          :  0.8.0 (OK)
pygments >=2.0               :  2.3.1 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
nbconvert >=4.0              :  5.4.1 (OK)
sphinx >=0.6.6               :  1.8.5 (OK)
pylint >=0.25                :  2.3.1 (OK)
psutil >=0.3                 :  5.6.1 (OK)
qtawesome >=0.5.7            :  0.5.7 (OK)
qtpy >=1.5.0                 :  1.7.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.0.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.8.0 (OK)
spyder_kernels >=1.8.0;<2.0.0:  1.8.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.3 (OK)
cython >=0.21                :  0.29.6 (OK)
IPython >=4.0                :  7.4.0 (OK)
matplotlib >=2.0.0           :  3.0.3 (OK)
pandas >=0.13.1              :  0.24.2 (OK)
numpy >=1.7                  :  1.16.2 (OK)
scipy >=0.17.0               :  1.2.1 (OK)
pyls >=0.31.0;<0.32.0        :  0.31.1 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
```



Discussion:
> this error is coming up when i access a folder or a file.

Are you trying to access a network folder?
Nope. a normal folder

On Thu, Nov 21, 2019, 16:01 Carlos Cordoba <notifications@github.com> wrote:

> this error is coming up when i access a folder or a file.
>
> Are you trying to access a network folder?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/10785?email_source=notifications&email_token=AFM3TJC3RQBTYNFXHYLHZJTQU2IFJA5CNFSM4JP63A7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE2KGBA#issuecomment-557097732>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AFM3TJHJLTZ2LJYQMSJ2Y6TQU2IFJANCNFSM4JP63A7A>
> .
>

It doesn't look like, because the error shows

> '\\\\\\\\fs01\\\\users\\\\ora\\\\Python Scripts\\\\HS_Scanner'

and that doesn't start with `C:\` or `D:\`.

Please share a screenshot that shows the path to that folder.
You're right... My mistake, it is a network folder

On Thu, Nov 21, 2019, 17:20 Carlos Cordoba <notifications@github.com> wrote:

> It doesn't look like, because the error shows
>
> '\\\\fs01\\users\\ora\\Python Scripts\\HS_Scanner'
>
> and that doesn't start with C:\ or D:\.
>
> Please share a screenshot that shows the path to that folder.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/10785?email_source=notifications&email_token=AFM3TJD7OSEDUPRUUBHT5YLQU2RLLA5CNFSM4JP63A7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE2SRQI#issuecomment-557131969>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AFM3TJC6XZ6ZCXDSSEF6Q23QU2RLLANCNFSM4JP63A7A>
> .
>

We'll fix this in a future version. For now, please use a regular directory.
@dalthviz, please take a look at this one.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py
--- a/spyder/plugins/ipythonconsole/widgets/shell.py
+++ b/spyder/plugins/ipythonconsole/widgets/shell.py
@@ -10,6 +10,7 @@
 
 # Standard library imports
 import os
+import os.path as osp
 import uuid
 from textwrap import dedent
 
@@ -166,9 +167,10 @@ def is_spyder_kernel(self):
 
     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"\\\\")
+            # Use normpath instead of replacing '\' with '\\'
+            # See spyder-ide/spyder#10785
+            dirname = osp.normpath(dirname)
 
         if self.ipyclient.hostname is None:
             self.call_kernel(interrupt=True).set_cwd(dirname)


Test patch: