Steve Dower added the comment:

Issue #27731 will resolve this for the latest versions of Windows 10, but if we 
want to support this for earlier versions of Windows here's the algorithm I'd 
suggest:

* if len(path) < 260 - we're good, don't do anything
* get the last '\' or '/' character before the 260th character and split the 
path into two parts (path1 and path2)
* use CreateFile to get a handle to path1, then GetFinalPathNameByHandle to get 
a normalized npath1 (which will have the '\\?\' prefix)
* split path2 by '/' and '\' characters, trim leading and trailing spaces from 
each segment, trim trailing dots from each segment, and append them to npath1 
separated by '\' characters
* use this normalized path instead of path

It's a relatively expensive operation, but it is the most reliable way to 
normalize a path. The place where it'll fall down is that trimming spaces and 
trailing dots and replacing '/' with '\' is not guaranteed to be the only 
processing that is done. However, it should solve 99% of cases which is better 
than the 0% that currently work.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27730>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to