I have a directory dir
which contains 3 files: f1.txt
, f2.txt
, f3.pngt
.
I want to create a zip archive given the path of that directory where each file will be a zip archive. The resulting zipped_archive.zip
should be on the same path as the dir
is.
That is, I want the zipped_archive.zip
to contain f1.zip
, f2.zip
, f3.zip
where each of these f#.zip
files contains the correspondingly-named txt
or png
file.
The above is better illustrated with this file-structure:
tmp
|
+-- dir
| |
| +-- f1.txt
| +-- f2.txt
| +-- f3.txt
|
+-- zipped_archive.zip
| |
| +-- f1.zip
| | |
| | +-- f1.txt
| +-- f2.zip
| | |
| | +-- f2.txt
| +-- f3.zip
| | |
| | +-- f3.png
I have tried to apply zipfile
as seen in this answer and shutil
as seen this answer, both from the same question. I though of using shutil.make_archive
on each file and in the end do a ziph.write
with that result but I struggle to make it work and got confused.
Can someone suggest/provide some example code to help me understand how this works?