I hope the title is not too confusing. Please have a look at the picture and gif below.
Say I had a directory like this. Now I want to zip all folders that match "cs-", "es-", "fr-", and so forth, like in the gif below:
EDIT: All folders have several more subfolders and/or files.
So far I managed to find all folders I want:
import zipfile, os, shutil, pprint
from pathlib import Path
userPath1 = Path(input("Please give me a path:",))
# '- set(userPath1.glob("*.*")' is deducted so that only folders (and no files) are stored in the variables
csFileServerFileList = list(set(userPath1.glob('cs-*')) - set(userPath1.glob("*.*")))
esFileServerFileList = list(set(userPath1.glob('es-*')) - set(userPath1.glob("*.*")))
frFileServerFileList = list(set(userPath1.glob('fr-*')) - set(userPath1.glob("*.*")))
itFileServerFileList = list(set(userPath1.glob('it-*')) - set(userPath1.glob("*.*")))
jaFileServerFileList = list(set(userPath1.glob('ja-*')) - set(userPath1.glob("*.*")))
nlFileServerFileList = list(set(userPath1.glob('nl-*')) - set(userPath1.glob("*.*")))
plFileServerFileList = list(set(userPath1.glob('pl-*')) - set(userPath1.glob("*.*")))
ptFileServerFileList = list(set(userPath1.glob('pt-*')) - set(userPath1.glob("*.*")))
ruFileServerFileList = list(set(userPath1.glob('ru-*')) - set(userPath1.glob("*.*")))
trFileServerFileList = list(set(userPath1.glob('tr-*')) - set(userPath1.glob("*.*")))
langFileServerList = [
csFileServerFileList, esFileServerFileList, frFileServerFileList, itFileServerFileList,
jaFileServerFileList, nlFileServerFileList, plFileServerFileList, ptFileServerFileList,
ruFileServerFileList, trFileServerFileList
]
for list in langFileServerList:
for i in list:
print(i)
I know about this method:
>>> newZip = zipfile.ZipFile('new.zip', 'w')
>>> newZip.write('spam.txt', compress_type=zipfile.ZIP_DEFLATED)
>>> newZip.close()
But it only works with files and not with folders.
I'd be very grateful for your help!