File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Folder - to - Zip
2
+
3
+ ## Utility
4
+
5
+ * To convert folders into ZIP format
6
+
7
+ ## How to use
8
+
9
+ * ### Step 1
10
+
11
+ > Put the folder you want to convert in the same directory
12
+
13
+ * ### Step 2 -> Run the script
14
+
15
+ Windows:
16
+
17
+ > py folder-to-zip.py
18
+
19
+ Linux:
20
+
21
+ > python3 folder-to-zip.py
22
+
23
+ ## You're all set! The Zip file for the selected folder will be created
Original file line number Diff line number Diff line change
1
+ import os
2
+ import zipfile
3
+ from random import randrange
4
+
5
+
6
+ def zip_dir (path , zip_handler ):
7
+ for root , dirs , files in os .walk (path ):
8
+ for file in files :
9
+ zip_handler .write (os .path .join (root , file ))
10
+
11
+
12
+ if __name__ == '__main__' :
13
+ to_zip = input ("""
14
+ Enter the name of the folder you want to zip
15
+ (N.B.: The folder name should not contain blank spaces)
16
+ >
17
+ """ )
18
+ to_zip = to_zip .strip () + "/"
19
+ zip_file_name = f'zip{ randrange (0 ,10000 )} .zip'
20
+ zip_file = zipfile .ZipFile (zip_file_name , 'w' , zipfile .ZIP_DEFLATED )
21
+ zip_dir (to_zip , zip_file )
22
+ zip_file .close ()
23
+ print (f'File Saved as { zip_file_name } ' )
You can’t perform that action at this time.
0 commit comments