简体   繁体   中英

Changing the directory using os.chdir UNC filepath in python

I am attempting to change a directory via its IP address or using it's unc (as I am working in windows). This is due to the external server being mapped to different drives for different users.

Using os.chdir(r'path\\\\to\\remote\\directory') does not seem to work and I wonder if there are any alternatives that python doesn't hate ie an IP address?

Works fine for me:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.chdir(r"\\myserver\myshare")
>>> os.getcwd()
'\\\\myserver\\myshare'

It's hard to tell if the r'path\\\\to\\remote\\directory' typo is also in your actual code and how you determined it "does not work".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM