newbie pisan
newbie pisan

Reputation: 327

Python - how to read path file/folder from server

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.

Upvotes: 10

Views: 44850

Answers (2)

Adrien Plisson
Adrien Plisson

Reputation: 23293

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

Upvotes: 0

johnsyweb
johnsyweb

Reputation: 141840

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')

Upvotes: 8

Related Questions