I have found out that you can't open(filepath)
when filepath length is greater than 255 characters even if the filename itself is 10 characters long (the remaining part is the directory path).
Any idea to work around this issue? (python 2.6 on win32)
The most general approach to this is to prefix the path with \\\\?\\
(reference). Be aware that this disables certain pre-processing on the path, but nothing major IMO.
Also I can note that on 32-bit Windows Server 2003 with Python 2.7 I had to use prefixed Unicode path (u"\\\\\\\\?\\\\"
prefix or ur"\\\\?\\"
) since (as mentioned in reference) non-Unicode API functions may still be limited to MAX_PATH
length even though the prefix is used.
e.g., ur"\\\\?\\c:\temp\....\abc.txt"
A Windows OS level solution is to use the DOS SUBST command to define a pseudo drive at a particular directory.
SUBST Q: C:\really\long\path\name\full\of\sub\directories
Then you can access the files in that directory as Q:filename
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With