Skip to content

Commit 2eb0851

Browse files
committed
finish organizing files
1 parent e420918 commit 2eb0851

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Modules/OrganizingFiles/lesson_plan.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,24 @@ exampleZip.close()
115115
# exampleZip.extract('zergRush.jpg', 'some_other_dir')
116116
```
117117

118+
### Creating and Adding to ZIP files
119+
To create a compressed ZIP file, open the ZipFile object with 'w' to write.
120+
Use the write() method to compress a file and add it to the zipfile. The first
121+
argument is the name of the file, and the second argument is the compression
122+
type (just keep it as zipfile.ZIP_DEFLATED). This will erase any existing ZIP
123+
file. If you want to append, or add to a ZIP file, pass 'a' for append.
124+
```python
125+
import zipfile
126+
newZip = zipfile.ZipFile('new.zip', 'w')
127+
newZip.write('zergRush.jpg', compress_type=zipfile.ZIP_DEFLATED)
128+
newZip.close()
129+
```
130+
131+
# Activity
132+
# Summary
133+
The os and shutil modules provides functions for copying, moving, renaming, and
134+
deleting files. When wanting to perform operations on every file and folder
135+
within a directory, use the os.walk() function. The zipfile module allows you
136+
to compress and extract .zip files. All together, we can use this to make a
137+
basic backup script
138+

0 commit comments

Comments
 (0)