votes up 4

Can't listdir a file

Package:
Exception Class:
ValueError

Raise code

    def exists(self):
        return self.at 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, self.at)
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

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