python win32文件名长度解决方法 [英] python win32 filename length workaround

查看:29
本文介绍了python win32文件名长度解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现当文件路径长度大于 255 个字符时,您无法 open(filepath) 即使文件名本身是 10 个字符长(其余部分是目录路径).

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).

有解决此问题的方法吗?(python 2.6 on win32)

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

推荐答案

最常用的方法是在路径前加上 \\\\?\\ (参考).请注意,这会禁用路径上的某些预处理,但不是主要的 IMO.

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.

我还注意到,在带有 Python 2.7 的 32 位 Windows Server 2003 上,我必须使用带前缀的 Unicode 路径(u"\\\\\\\\?\\\\" 前缀或 ur"\\\\?\\") 因为(如 reference) 即使使用了前缀,非 Unicode API 函数仍可能被限制为 MAX_PATH 长度.

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.

例如,ur"\\\\?\\c:\temp\....\abc.txt"

这篇关于python win32文件名长度解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆