1

I am currently refactoring some old Python code and stumbled across this construct:

abspath = '\\\\?\\' + os.path.abspath(path)

Can anyone explain the possible use of the prefix? I would like to get rid of it but I am not sure whether it solves some strange corner case, like UNC network path access or something similar.

If it helps, we are only developing on Windows, so I can rule out that the prefix handles some non-Windows os-specific case.

Cerno
  • 751
  • 4
  • 14
  • Each pair of backslashes becomes a single backslash because of escaping, so it's actually just ```\\?\```. But I can't think of what that's for. – Barmar Mar 13 '20 at 00:02
  • Thanks for the input. I understood that part, but the use is fairly puzzling. It doesn't break anything, so I would assume that it has some use in Python. – Cerno Mar 13 '20 at 00:07
  • I doubt it means anything special to Python. Pathnames are handled by the OS.' – Barmar Mar 13 '20 at 00:09
  • It lets you get around the 260 character maximum that the Microsoft Windows API has for file system paths. Other restrictions apply, such as not using forward slashes, or relative directories. Use `\\?\UNC` prefix for unc path names and `\\?\D:\` (for example) for paths. Several SO questions cover this, like https://stackoverflow.com/questions/21194530/what-does-mean-when-prepended-to-a-file-path – tdelaney Mar 13 '20 at 00:13
  • @tdelaney Thanks a lot. I wasn't able to find it by searching for \\?\, thanks for the clarification. – Cerno Mar 13 '20 at 00:20
  • I linked to another question that I think has all the info and marked this one as a duplicate. Future searchers can look at that one and get the info they need. – tdelaney Mar 13 '20 at 00:20
  • @tdelaney Perfect, thanks. – Cerno Mar 13 '20 at 01:09

0 Answers0