Jan-07-2022, 01:50 PM
(Jan-06-2022, 11:28 PM)bowlofred Wrote: And I have to turn the generator into a list to get the lengthWe need len_consume :-D
import pathlib # this works unc1 = pathlib.PureWindowsPath(r"\\host\share\file1") # this seems to work also unc2 = pathlib.PureWindowsPath(r"\\host\share") / "file1" # the pathlib has support for unc paths, but only if the full path to the share is used # concatenating the host part with share part will not work. unc3 = pathlib.PureWindowsPath(r"\\host") / "share/dir/file" print("OK", unc1) print("OK", unc2) print("FAIL", unc3)
Output:OK \\host\share\file1
OK \\host\share\file1
FAIL \host\share\dir\file
I used PureWindowsPath
because I'm on a Linux system.For my understanding, it is important, that the
str
itself has the right format.This is ok:
print(r"\\host\share\file1")
Output:\\host\share\file1
This is not ok:print("\\host\share\file1")
Output:\host\share
ile1
The first \
escapes the second backslash, if a raw string literal is not used.The
\f
is the control character Form Feed
.Working with backslashes in string literals without the
r
-prefix, will cause problems.The second important thing for UNC paths is, that they must supply in following structure:
\\host\share
.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!