1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#!/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()
|