1
I’m trying to make a python script to zip xls files. I managed to get it inside directory and is adding everything inside a file .zip
. However I wanted it to go through all subdirectories and be able to bring only the . xls files and not the folders with the files.
Ex:
The path would be that:
C:/Folder/subfolder/201803
Inside the path I have numbering folders, e.g.:
C:/Folder/subfolder/201803/01
C:/Folder/subfolder/201803/02
and inside these folders I have the . xls files.
xmlzip = zipfile.ZipFile(pathfile, 'w')
for folder, subfolder, files in os.walk(path):
for file in files:
if file.endswith('.xls'):
xmlzip.write(os.path.join(folder, file), os.path.relpath(os.path.join(folder, file), path), compress_type = zipfile.ZIP_DEFLATED)
xmlzip.close()
Perfect friend. Thank you very much, I had already tested several ways and it had not worked. I think I missed understand the same structure. Thank you very much.
– Henrique Nascimento