Feb-11-2020, 04:27 PM
Okay I will try to explain this as best as I can. My goal is to create a python script that will loop through folders, zip them up, but NOT nest the folder inside the zip file. For example: the zip file structure cannot produce Cat.zip/Cat/catnip.jpg but produces Cat.zip/catnip.jpg.
There is a parent Folder called:
Original_Raw_Data
--620_PANO_1_20190802 #subfolder that need zipped
-contents
--787_PANO_1_20190802 #subfolder that need zipped
--788_PANO_1_20190802 #subfolder that need zipped
When you zip a folder manually the structure goes
788_PANO_1_20190802.ip/788_PANO_1_20190802/file.txt
I am trying
788_PANO_1_20190802.zip/file.txt
Currently my code is as follows
Any help would be appreciated!
There is a parent Folder called:
Original_Raw_Data
--620_PANO_1_20190802 #subfolder that need zipped
-contents
--787_PANO_1_20190802 #subfolder that need zipped
--788_PANO_1_20190802 #subfolder that need zipped
When you zip a folder manually the structure goes
788_PANO_1_20190802.ip/788_PANO_1_20190802/file.txt
I am trying
788_PANO_1_20190802.zip/file.txt
Currently my code is as follows
Any help would be appreciated!
>>> import os >>> import zipfile >>> zf = zipfile.ZipFile("620_PANO_1_20190802.zip", "w") >>> for dirname, subdirs, files in os.walk("P:\Standards\Tools_and_Scripts\ZipFolderTools\Original_Raw_Data\620_PANO_1_20190802"): for filename in files: zf.write(os.path.join('620_PANO_1_20190802', filename) zf.close()