#!/usr/bin/env python3 import os,sys,re from subprocess import call def parcours (cible,fichierdir,init): if os.path.isdir(cible): liste=os.listdir(cible) for fichier in liste : fichier = cible+"/"+fichier parcours(fichier,fichierdir,init) else : tmp = open(cible,'rb') if init[0]=="/" : fichierdir.write(b"\n--"+bytes(cible[len(re.search("(^\/.*\/).+",init).group(0))+1:],'UTF-8')+b"--\n") else : fichierdir.write(b"\n--"+bytes(cible,"UTF-8")+b"--\n") print(cible) byte=tmp.read() fichierdir.write(byte) tmp.close() if len(sys.argv)!= 2 : print("Parametres incorrects, syntaxe : ./compact.py fichier\n") exit() cible = sys.argv[1] fichier = open(".compactageencours",'ab') parcours(cible,fichier,cible) destination = re.search("(\w+\.?\w+)$",sys.argv[1]).group(1)+".comp" call(["./huf", ".compactageencours", destination]) call(["rm",".compactageencours"]) fichier.close()