Monday, April 21, 2025

Compress Multiple Files in One ZIP File - Python

import zipfile, os

handle = zipfile.ZipFile('ALL-PYD.zip', 'w')

os.chdir('c:\\Python38-64\\DLLs')

for x in os.listdir():
    if x.endswith('.pyd'):
        handle.write(x, compress_type = zipfile.ZIP_DEFLATED)

handle.close()

This Python script creates a new ZIP archive file named ALL-PYD.zip in the current working directory. It then changes the current working directory to c:\Python38-64\DLLs. For each file in the directory that has a .pyd extension, it adds the file to the ZIP archive using the write() method of the ZipFile object. The files are compressed using the ZIP_DEFLATED compression method. Finally, it closes the ZIP archive.

So, this script is used to create a compressed archive of all the files in the c:\Python38-64\DLLs directory with a .pyd extension, making it easier to transfer or distribute the files.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...