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.
getcwd() method is used for getting the Current Working Directory in Python. The absolute path to the current working directory is returned in a string by this function of the Python OS module.
dirname() Use os. path. dirname() to get the directory folder (name) from a path string.
In order to obtain the Current Working Directory in Python, use the os. getcwd() method. This function of the Python OS module returns the string containing the absolute path to the current working directory.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With