Using Python, how can I access a shared folder on windows network?

Question:

I have a file that I would like to copy from a shared folder which is in a shared folder on a different system, but on the same network. How can I access the folder/file? The usual open() method does not seem to work?

Asked By: BrickByBrick

||

Answers:

Use forward slashes to specify the UNC Path:

open('//HOST/share/path/to/file')

(if your Python client code is also running under Windows)

Answered By: johnsyweb

How did you try it? Maybe you are working with and omit proper escaping.

Instead of

open('\HOSTsharepathtofile')

use either Johnsyweb’s solution with the /s, or try one of

open(r'\HOSTsharepathtofile')

or

open('\\HOST\share\path\to\file')

.

Answered By: glglgl

I had the same issue as OP but none of the current answers solved my issue so to add a slightly different answer that did work for me:

Running Python 3.6.5 on a Windows Machine, I used the format

r"\DriveNamethenfilepathtxt.md"

so the combination of double backslashes from reading @Johnsyweb UNC link and adding the r in front as recommended solved my similar to OP’s issue.

Answered By: Andrew Peters

My remote server is on Linux Machine and the client on Windows. For me:

  1. glob.glob('//HOST/share/path/to/file') works with forward slash
  2. open(r'\HOSTsharepathtofile') and open('\\HOST\share\path\to\file') worked with backward slash
  3. For pd.read_csv(), forward or backward slash, doesn’t matter.
Answered By: Chowdhury
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.