3

I am having trouble using network addresses. Tried in Python3.6 with Windows. Invoking

os.path.relpath(r"\\ZEYCUS\first\second\file.txt", start=r"\\ZEYCUS\first")

I get 'second\\file.txt', as I would expect. But with

os.path.relpath(r"\\ZEYCUS\first\second\file.txt", start=r"\\ZEYCUS")

I get an error message: ValueError: path is on mount '\\\\ZEYCUS\\first', start on mount 'C:'.

What is going on? Where did the C: bit come from? How should I use relpath to obtain 'first\\second\\file.txt'?

zeycus
  • 860
  • 1
  • 8
  • 20

1 Answers1

2

That's because r'\\ZEYCUS' isn't actually an OS path. It is a network host specifier. Windows uses drive letters, inherited from DOS, between which there are no relative paths; relative paths only function within a drive. r"\\ZEYCUS\first" is a network volume, which operates like a drive. In effect that whole part turns into an implicit drive letter. C: would most likely be your system drive, possibly the current drive of the Python process. If you try just dir \\zeycus in Cmd you'll find that's an invalid volume syntax (in a rather unhelpful message) even though the same specifier in Explorer produces a volume listing.

Yann Vernier
  • 15,414
  • 2
  • 28
  • 26
  • @Vernier thanks, I tried and indeed it works as you say, I'm afraid my lack of network knowledge is showing here. – zeycus Nov 18 '17 at 10:56