import os
import string
import random
import zipfile
pool = string.ascii_lowercase + string.digits
root = 'outputForLab3'
count_file = 'filesize.txt'
zip_file = 'output3.zip'
file_size = 0
zip_size = 0
def random_select(k):
return ''.join(random.choices(pool, k=k))
print(pool)
if not os.path.exists(root):
os.mkdir(root)
for i in range(50):
rd = random_select(5)
with open(os.path.join(root, rd+'.txt'), 'w+') as f:
f.write(random_select(random.randint(10**3, 10**5)))
# pass
z = zipfile.ZipFile(zip_file, 'w')
with open(count_file, 'w+') as out:
for p, d, f in os.walk(root):
for file in f:
out.writelines(os.path.join(p, file)+' size:' +
str(os.path.getsize(os.path.join(p, file)))+'\n')
file_size += os.path.getsize(os.path.join(p, file))
z.write(os.path.join(p, file))
z.close()
zip_size = os.path.getsize(zip_file)
print(file_size, zip_size, file_size-zip_size, (file_size-zip_size)/file_size)