File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change 9
9
dir_name = 'tmp/' # update path
10
10
11
11
12
- def zipdir (path , zip ):
12
+ # def zipdir(path, zip):
13
+ # for root, dirs, files in os.walk(path):
14
+ # for file in files:
15
+ # zip.write(os.path.join(root, file))
16
+ #
17
+ # if __name__ == '__main__':
18
+ # zipfile = ZipFile(file_name, 'w')
19
+ # zipdir(dir_name, zipfile)
20
+ # zipfile.close()
21
+
22
+
23
+ today = datetime .now ()
24
+ file_name = 'zipper_' + today .strftime ('%Y.%m.%dh%H%M' ) + '.zip'
25
+ dir_name = 'tmp/' # update path
26
+
27
+ def add_folder_to_zip (folderPath ,zipFile ):
13
28
for root , dirs , files in os .walk (path ):
14
29
for file in files :
15
- zip .write (os .path .join (root , file ))
30
+ print (root )
31
+ full_path = os .path .join (root ,file )
32
+ zipfile .write (full_path )
16
33
17
- if __name__ == '__main__' :
18
- zipfile = ZipFile (file_name , 'w' )
19
- zipdir (dir_name , zipfile )
20
- zipfile .close ()
34
+ with ZioFile ("test_zip.zip" ,"w" ) as my_zip :
35
+ add_folder_to_zip ("testFoler8" ,my_zip )
You can’t perform that action at this time.
0 commit comments