dotfiles/scripts/unziptree

35 lines
890 B
Plaintext
Raw Normal View History

2018-10-06 10:27:36 +02:00
#!/usr/bin/env python
import os
import subprocess
for root, dirs, files in os.walk("."):
for name in files:
base, ext = os.path.splitext(name)
2019-01-06 14:05:05 +01:00
if name.endswith(".zip"):
cmd = ["unzip"]
elif name.endswith(".7z"):
cmd = ["7z", "e"]
elif name.endswith(".rar"):
cmd = ["unrar", "x"]
elif name.endswith('.tar'):
cmd = ["tar", "xf"]
elif name.endswith('.tar.gz'):
cmd = ["tar", "xzf"]
elif name.endswith('.tar.xz'):
cmd = ["tar", "xJf"]
else:
2018-10-06 10:27:36 +02:00
continue
filepath = os.path.join(root, name)
dirpath = os.path.join(root, base)
print(filepath)
os.mkdir(dirpath)
2019-01-06 14:05:05 +01:00
cmd.append(os.path.realpath(filepath))
2018-10-06 10:27:36 +02:00
r = subprocess.run(cmd, cwd=dirpath)
r.check_returncode()
os.unlink(filepath)