Created
December 27, 2019 12:43
-
-
Save jmora/44bfbe309c938e53f5c7dbe0dba152e1 to your computer and use it in GitHub Desktop.
Compress files (I need to use this somewhere else)
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
#!/usr/bin/python3 | |
import os, shutil, sys, subprocess | |
p = lambda *e: '/'.join(e) | |
def bash (*command): | |
c = ' '.join(command) | |
print('Doing ', c) | |
subprocess.Popen(c, stderr=sys.stdout, stdout=sys.stdout, shell=True).wait() | |
td = 'omgtempdir' | |
root = '.' | |
def processfile(d, f): | |
orig = p(d, f) | |
os.mkdir(td) | |
bash('unzip -q', orig, '-d', td) | |
os.chdir(td) | |
bash('zip -q -rp0', f, '*') | |
bash('mv', f, orig) | |
os.chdir('..') | |
bash('rm -rf', td) | |
if __name__ == "__main__": | |
child = sys.argv[-1] | |
tar = child + '.tar' | |
root = os.getcwd() | |
os.chdir(child) | |
for d, sds, fs in os.walk(p(root, child)): | |
for f in fs: | |
if f[-4:] in "pttx xlsx docx".split(): | |
print('Starting', p(d, f)) | |
processfile(d, f) | |
os.chdir(root) | |
bash('7za a -r -t7z -m0=lzma2 -mx=9 -mfb=273 -md=28 -ms=8g -mmt=off -mmtf=off -mqs=on -bt -bb3', child+'.7z', child) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment