0

I'm trying to extract archives of different types (such as: *.7zip, *.V3P, *.Q4P) to a specific folder with using a subprocess.

import subprocess

archname = "E:\\temp\\payments.zip"
dir7z = "C:\\Program Files\\7-Zip\\7z.exe"

def extractfiles(archname):
    system = subprocess.Popen([dir7z, "x", archname])
    return (system.communicate())

extractfiles(archname)

This code extracting files to the project folder, but I want extract them to the specific folder as "E:\temp\". I know 7zip command on the Windows command line:

7z x E:\temp\payments.zip -o"E:\temp\"

Please, help me implement that 7zip command from Python

Helma
  • 1

1 Answers1

0

I think you can do this using the "os" library:

import os
os.system("""7z x E:\\temp\payments.zip -o"E:\\temp\\"""")

Basically runs the given command like you would in command prompt

  • I tried this one. displays: '"C:\Program" �� ���� ����७��� ��� ���譥� ��������, �ᯮ��塞�� �ணࠬ��� ��� ������ 䠩���. Process finished with exit code 0' but I can't find extracted files in the E:\\temp\\ – Helma Apr 27 '21 at 13:54
  • Well that's weird, since it basically runs the command in the command prompt as you would from keyboard, to clarify, does the command work when you enter it manually? – GetTwoBirdsStonedAtOnce Apr 27 '21 at 13:59