votes up 4

Can't listdir a file

Exception Class:

Raise code

    def exists(self):
        return in self.root._name_set()

    def iterdir(self):
        if not self.is_dir():
            raise ValueError("Can't listdir a file")
        subs = map(self._next, self.root.namelist())
        return filter(self._is_child, subs)

    def __str__(self):
        return posixpath.join(self.root.filename,
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 0 votes down

Summary: make sure you use a slash at the end of the path your want to iter over:

Code to reproduce (WRONG):

import zipp, io

data = io.BytesIO()
zf = zipp.zipfile.ZipFile(data'w')
zf.writestr('fol/file.txt''content of a')

p = zipp.Path(zf, 'fol')

print('List of files', list(p.iterdir()))

Working version (Fixed):

import zipp, io

data = io.BytesIO()
zf = zipp.zipfile.ZipFile(data, 'w')
zf.writestr('fol/file.txt''content of a')

p = zipp.Path(zf, 'fol/') # <--- HERE IS A FIX WE ADDED SLASH

print('List of files', list(p.iterdir()))

May 16, 2021 ivictbor answer

Add a possible fix

Please authorize to post fix