Created
October 7, 2022 12:21
-
-
Save synodriver/0a18f15b92eb77b189b8b6c19f4ab82a to your computer and use it in GitHub Desktop.
shutil with rar support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
os.environ["UNRAR_LIB_PATH"] = r"C:\Program Files (x86)\UnrarDLL\x64\UnRAR64.dll" | |
import shutil | |
from unrar import rarfile | |
from pprint import pprint | |
def _unpack_rarfile(filename, extract_dir): | |
# todo: password? | |
if not rarfile.is_rarfile(str(filename)): | |
raise shutil.ReadError("%s is not a rar file" % filename) | |
rar = rarfile.RarFile(filename) | |
rar.extractall(extract_dir) | |
shutil.register_unpack_format("rar", [".rar"], _unpack_rarfile, [], "uncompressed rar file") | |
def main(): | |
pprint(shutil.get_unpack_formats()) | |
shutil.unpack_archive(r"your file name", r"your dist path") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment