This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.isfile fails on path exactly 260 Chars long in Windows
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.9
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, paul.moore, serhiy.storchaka, steve.dower, tim.golden, ubermidget2, zach.ware
Priority: normal Keywords:

Created on 2021-08-26 12:41 by ubermidget2, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg400341 - (view) Author: Luke Rossi (ubermidget2) Date: 2021-08-26 12:41
I saw 33105, but believe this to be a different issue as path length 260 is valid.

I did testing by crafting a path that is exactly 260 by hand - A path 259 in length reports .isfile() as True.
msg400342 - (view) Author: Luke Rossi (ubermidget2) Date: 2021-08-26 12:44
I saw 33105, but believe this to be a different issue as path length 260 is valid.

I did testing by crafting a path that is exactly 260 by hand - A path 259 in length reports .isfile() as True.

The Stack Error:
[WinError 3] The system cannot find the path specified
msg400353 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-08-26 15:06
The legacy maximum buffer size is 260 characters, but remember that strings in C are terminated by a null character (i.e. "\0"). So the maximum path length is actually 259 characters when opening files. 

In Windows 10 with Python 3.6+, you can enable the `LongPathsEnabled` system setting to extend the limit up to about 32760 characters. In many cases you can also use the "\\\\?\\" extended-path prefix to access a long path (e.g. r"\\?\C:\some\long\path"), but the path has to be fully qualified and can only use backslash as the separator, not forward slash.
msg400413 - (view) Author: Luke Rossi (ubermidget2) Date: 2021-08-27 11:05
What an annoying edge case - makes sense that there isn't an easy fix.

The extended path prefix worked perfectly - thanks
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89176
2021-09-16 22:56:44steve.dowersetstatus: open -> closed
resolution: third party
stage: resolved
2021-08-27 11:05:05ubermidget2setmessages: + msg400413
2021-08-26 15:06:25eryksunsetnosy: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg400353
components: + Windows
2021-08-26 12:44:37ubermidget2setmessages: + msg400342
2021-08-26 12:41:25ubermidget2create