1

I tried to list all files inside 7z archive (I don't want to extract them).

I followed the documentation of the creators of py7zr.

My code look like this:

def checkArchive(archivePath):
for filename in os.listdir(archivePath):
    print("Filename is: " + filename)
    cmd = "py7zr l " + filename
    os.system(cmd)

I also tried cmd = python -m "py7zr l " + filename as a cmd command.

But no matter what command I use, the program always returns an error: not a 7z file.

I made sure and I know that all files on which the command operates have the extension 7z.

How can I get py7zr to start recognizing the file type? Or is there any other way to list the 7zarchive?

1 Answers1

1

I think can use this to list files in a 7z archive.

import py7zr

with py7zr.SevenZipFile(r'<PATH TO 7Z FILE>.7z', 'r') as archive:
    all_paths = archive.getnames()