How to zip up files of same prefix in python?
Question: If I have a directory "C:\Files" that contains a bunch of files:

A_File1 A_File2 B_File1 B_File2

What is the best way to iterate through the files to zip up any file with the
same prefix into a single zip file? For instance, output would be "A.zip" and
"B.zip" and their associated files.

I know how to iterate through the files:

    
    
    for item in os.listdir("C:\FILES"):
    

But I do not know what the best way to zip up the files is or if there is some
python library that helps with that.


Answer: Use the glob module from the standard library, instead of os.listdir:

    
    
    from glob import glob
    
    for file in glob("C:\\FILES\\A_File*"):
        ...
    

(If you are using backslashes to separate dirs, use two, because a single one
is a escape character in Python strings)

