'Python Zipfile extractall IOError on Windows when extracting files from long paths
I'm running python zipfile extractall, its extracting to a path which is longer than 255 characters. Running this on windows 7 64bit.
I'm getting to following error [Errno 2] No such file or directory: u'
Any ideas ?
Its a network folder i want to extract from/to. So I mounted the folder as a network drive t:\ this solved the issue for the time being.
Solution 1:[1]
This worked for me:
class ZipfileLongPaths(zipfile.ZipFile):
def _extract_member(self, member, targetpath, pwd):
targetpath = winapi_path(targetpath)
return zipfile.ZipFile._extract_member(self, member, targetpath, pwd)
Where winapi_path is:
def winapi_path(dos_path, encoding=None):
path = os.path.abspath(dos_path)
if path.startswith("\\\\"):
path = "\\\\?\\UNC\\" + path[2:]
else:
path = "\\\\?\\" + path
return path
winapi_path taken from pathname too long to open?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |