Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python win32 filename length workaround

Tags:

python

windows

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)

like image 834
user246456 Avatar asked Aug 24 '10 10:08

user246456


2 Answers

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"

like image 130
Luke Avatar answered Oct 04 '22 03:10

Luke


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.

like image 37
PaulMcG Avatar answered Oct 04 '22 04:10

PaulMcG