0
Follow
0
View

How to avoid subfolders creation while zipping files?

dxk85503302 注册会员
2023-01-25 17:59

According to: [Python.Docs]: zipfile - ZipFile.write(filename, arcname=None, compress_type=None, compresslevel=None) ( is mine):

So you should use:

zipF.write(file, arcname=os.path.basename(file), compress_type=zipfile.ZIP_DEFLATED)

If expanding the functionality (to include files from multiple folders) is in plan, you should pay attention to duplicate file base names (in different folders).

About the Author

Question Info

Publish Time
2023-01-25 17:59
Update Time
2023-01-25 17:59