Command line for 7z to extract specific files from specific folders inside an archive

You can specify a file/folder filter at the end of the command line. Check this for more details on 7zip command line commands and options.

7z.exe x [archive.7z] -o[output_dir] [filter]

e.g. 7z.exe x abc.7z -aoa -oC:\Temp system

You can also specify files of a particular type from system folder. For e.g. system\*.exe will extract all .exe files inside the system directory.

-aoa option is for overwrite mode.

To call it from Python you can use subprocess module. Something like:

import subprocess

cmd = []
cmd.append(r'C:\Program Files\7-Zip\7z.exe')
cmd.append('x')
cmd.append(archive)
cmd.append('-aoa')
cmd.append('-o{}'.format(dst_part))
cmd.append(file_folder_filter)
subprocess.call(cmd)

Steps to extract a specific directory from 7z zip:

Specific Directory: rootdir/firstson/second

Zip file : test.7z

Command to use :

7z x test.7z rootdir/firstson/second