Accessing networked file locations with pathlib

The server name by itself is not a valid component of a UNC path. You must also include a share. So path = Path('//server-01/directory', 'file') will work. It should resolve and return True when you run path.exists().

Microsoft docs here: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dfsc/149a3039-98ce-491a-9268-2f5ddef08192


If you create your path as:

path = Path('//server-01/directory/filename.txt')

instead of comma separating each directory it will work.

Tags:

Python

Pathlib