4

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Atti
  • 380
  • 4
  • 21
  • Make sure that the file exists, first of all. And second, try `import os; os.getcwd()` and make sure the path that it gives you is the directory where the file in question exists. – naiveai Nov 04 '16 at 09:46
  • the file exists, if i run it with the workaround mentioned above it works. – Atti Nov 04 '16 at 11:14

1 Answers1

9

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?

Community
  • 1
  • 1