Eryk Sun <eryk...@gmail.com> added the comment: > the UNC path is not really useful anywhere in the Python > standard library
UNC paths can be used almost anywhere in the file API. What specifically isn't working? > there’s no way to turn the it (back) into network drive once you > call resolve() Without using ctypes or PyWin32, you could resolve the root directory on drives A-Z to find the shortest matching path. This would also work with SUBST drives. For example: def resolve_mapped(path): path = pathlib.Path(path).resolve() mapped_paths = [] for drive in 'ZYXWVUTSRQPONMLKJIHGFEDCBA': root = pathlib.Path('{}:/'.format(drive)) try: mapped_paths.append(root / path.relative_to(root.resolve())) except (ValueError, OSError): pass return min(mapped_paths, key=lambda x: len(str(x)), default=path) ---------- nosy: +eryksun type: -> enhancement _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32442> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com