I'm trying to make a script with python to zip xls files. I've been able to get it into the directory and it's adding everything inside a .zip
file. But I wanted it to go through all the subdirectories and only bring the .xls files and not the folders with the files.
Ex:
The path would be this:
C: / folder / subfolder / 201803
Inside the path I have numbered folders, eg:
C: / folder / subfolder / 201803/01
C: / folder / subfolder / 201803/02
and within those 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()