9
votes

Using Python, how might one read a file's path from a remote server? This is a bit more clear to me on my local PC.

2
Your question is very unclear. Could you provide an example of what you want to achieve? - Björn Pollex

2 Answers

8
votes

See Reading and Writing Files in the Python Tutorial, which is a great place to start for a newbie.

Be sure to escape your backslashes on Windows, viz:

f=open('\\\\SERVER\\share\\file.ext', 'r')

or use "raw" strings:

f=open(r'\\SERVER\share\file.ext', 'r')
0
votes

use the os.path module to manipulate path string (you need to import os)

  • the current directory is os.path.abspath(os.curdir)
  • join 2 parts of a path with os.path.join(dirname, filename): this will take care of inserting the right path separator ('\' or '/', depending on the operating system) for building the path