|
3 | 3 | from zipfile import ZipFile |
4 | 4 |
|
5 | 5 |
|
6 | | -# set file name and time of creation |
| 6 | +# # set file name and time of creation |
| 7 | +# today = datetime.now() |
| 8 | +# file_name = 'zipper_' + today.strftime('%Y.%m.%dh%H%M') + '.zip' |
| 9 | +# dir_name = 'tmp/' # update path |
| 10 | +# |
| 11 | +# |
| 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 | + |
7 | 24 | today = datetime.now() |
8 | 25 | file_name = 'zipper_' + today.strftime('%Y.%m.%dh%H%M') + '.zip' |
9 | 26 | dir_name = 'tmp/' # update path |
10 | 27 |
|
11 | | - |
12 | | -def zipdir(path, zip): |
13 | | - for root, dirs, files in os.walk(path): |
| 28 | +def add_folder_to_zip(folderPath,zipFIle): |
| 29 | + for root,dirs,files in os.walk(folderPath): |
14 | 30 | for file in files: |
15 | | - zip.write(os.path.join(root, file)) |
| 31 | + print(file) |
| 32 | + print(root) |
| 33 | + full_path=os.path.join.join(root,file) |
| 34 | + zipFile.write(full_path) |
| 35 | + |
| 36 | +with ZipFile("test_zip.zip","w") as my_zip: |
| 37 | + add_folder_to_zip("Desktop",my_zip) |
16 | 38 |
|
17 | | -if __name__ == '__main__': |
18 | | - zipfile = ZipFile(file_name, 'w') |
19 | | - zipdir(dir_name, zipfile) |
20 | | - zipfile.close() |
|
0 commit comments