Search code examples
pythonzippython-zipfile

How to get meta-data of files inside compressed folder



I am trying to build a script written in Python which explore an archive (in this case a zip), and recursively gets all meta-data of files.
I usually use the following command to get meta-data:

(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(fname)

The problem is that I don't want to extract the files from the zip, so I don't have a path to provide to os.stat(). The only thing I am able to do is:

z=zipfile.ZipFile(zfilename,'r')
    for info in z.infolist():
        fname = info.filename
        data = z.read(fname)

Can I use the 'data' to get informations I need? or should I use another approach?


Solution

  • The ZIP format doesn't contain nearly as much metadata as a file on the filesystem (nor does it need to). You can extract all metadata from a zipfile without decompressing the file contents.

    The ZipFile.infolist() method gives you a list of ZipInfo instances, giving you access to that metadata.