import subprocess, pathlib for file in pathlib.Path("stackexchange").glob("*.7z"): subprocess.call(["7z","e","-y",file, f'-o{file.with_suffix("")}'])