I found myself in a situation where I had to use 7z, and I also needed to know exactly which files were extracted from each zip archive. To handle this, you can check the output of the 7z call and look for the file names. Here is the output of 7z:
$ 7z l sample.zip 7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21 p7zip Version 16.02 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64) Scanning the drive for archives: 1 file, 472 bytes (1 KiB) Listing archive: sample.zip -- Path = sample.zip Type = zip Physical Size = 472 Date Time Attr Size Compressed Name ------------------- ----- ------------ ------------ ------------------------ 2018-12-01 17:09:59 ..... 0 0 sample1.txt 2018-12-01 17:10:01 ..... 0 0 sample2.txt 2018-12-01 17:10:03 ..... 0 0 sample3.txt ------------------- ----- ------------ ------------ ------------------------ 2018-12-01 17:10:03 0 0 3 files
and how to parse this output using Python:
import subprocess def find_header(split_line): return 'Name' in split_line and 'Date' in split_line def all_hyphens(line): return set(line) == set('-') def parse_lines(lines): found_header = False found_first_hyphens = False files = [] for line in lines:
source share