Python win32 file name length workaround

I found that you cannot open(filepath) when the file path is longer than 255 characters, even if the file name is 10 characters (the rest is the directory path).

Any idea to get around this? (python 2.6 on win32)

+4
source share
2 answers

The most common approach to this is to prefix the path with \\\\?\\ ( link ). Keep in mind that this disables certain preprocessing along the way, but nothing serious IMO.

I can also notice that on 32-bit Windows Server 2003 with Python 2.7 I had to use the Unicode prefix path (prefix u"\\\\\\\\?\\\\" or ur"\\\\?\\" ) because (as mentioned in the link ), non-Unicode API functions can still be limited to the length of MAX_PATH , even if the prefix is ​​used.

e.g. ur"\\\\?\\c:\temp\....\abc.txt"

+12
source

A solution at the Windows OS level should use the DOS SUBST command to determine the pseudo-disk in a specific directory.

 SUBST Q: C:\really\long\path\name\full\of\sub\directories 

You can then access the files in this directory as Q:filename .

0
source

All Articles