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.
Asked
Active
Viewed 4.1k times
10
-
3Your question is very unclear. Could you provide an example of what you want to achieve? – Björn Pollex Nov 12 '10 at 10:01
2 Answers
8
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')

johnsyweb
- 136,902
- 23
- 188
- 247
-
2Raw strings are nicer for Windows paths - `f=open(r'\\SERVER\share\file.ext', 'r')` – Chris Morgan Nov 12 '10 at 10:49
0
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

Adrien Plisson
- 22,486
- 6
- 42
- 73