Skip to content

Instantly share code, notes, and snippets.

@deibit
Last active June 8, 2021 17:23
Show Gist options
  • Save deibit/183611962061af42bfe3b834cb4521c0 to your computer and use it in GitHub Desktop.
Save deibit/183611962061af42bfe3b834cb4521c0 to your computer and use it in GitHub Desktop.
import os
import os.path
import rarfile
cwd = os.getcwd()
# Unrar all rar files
files = ['pdf','epub','azw3']
for rar in os.listdir(cwd):
if rar.endswith('.rar') and rarfile.is_rarfile(rar):
current = rarfile.RarFile(rar)
for name in current.namelist():
if any([name.endswith(ext) for ext in files]):
print("extracting ... %s" % name)
current.extract(name)
print("removing ... %s" % rar)
os.remove(rar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment