2

I am using python 3.4

I have a crawler that is extracting 7z Console SFX files and I wish to extract them programmatically.

Currently I have only been able to do so with a subprocess call:

import subprocess
seven_zip = r"C:\Program Files\7-Zip\7z.exe"
tempfile = r"temp.exe" # SFX Archive
subprocess.call(seven_zip + ' x ' + tempfile + ' -aoa')

This is problematic because users of this script may not have 7zip installed, or may have it installed in a different directory. Further, running a subprocess doesn't give me direct access to the extracted items like running a normal zFile extraction would. I can workaround this by extracting to a temporary directory then parsing the files in said directory, but that is cumbersome.

I am thinking there's got to be a way of extracting the 7z Console SFX files with Python (maybe something with pylzma?), but I can't seem to find any questions on the subject here.

Update: I've still had limited success using py7zlib. Again I note that this is intended for extracting SFX (executable) archives, and not a .7z archive. Perhaps there is an application for py7zlib for such files, but I'm unable to find any examples.

telemark
  • 81
  • 6
  • Have you tried: https://github.com/fancycode/pylzma/blob/master/py7zlib.py – Alastair McCormack Mar 27 '15 at 21:44
  • See accepted answer to question [_How to read from a text file compressed with 7z in Python_](http://stackoverflow.com/questions/20104460/how-to-read-from-a-text-file-compressed-with-7z-in-python) which shows how to use the `py7zlib` module to extract 7z files. – martineau Mar 27 '15 at 22:03
  • I've still had limited success, specifically as related to extracting 7z SFX files (they have a .exe extension, not a typical .7z one). Am I missing the obvious here? py7zlib doesn't seem to work in this case. – telemark Mar 30 '15 at 17:06

0 Answers0