Created
December 2, 2020 03:49
-
-
Save keineahnung2345/741a64b69097bdf18cbdeb150f5e1d10 to your computer and use it in GitHub Desktop.
A python script to compress files, ref: https://stackoverflow.com/questions/47438424/python-zip-compress-multiple-files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zlib | |
import zipfile | |
from tqdm import tqdm | |
#https://stackoverflow.com/questions/47438424/python-zip-compress-multiple-files | |
def compress(path, file_names): | |
print("Containing directory:") | |
print(path) | |
print("File Paths:") | |
print(file_names) | |
# Select the compression mode ZIP_DEFLATED for compression | |
# or zipfile.ZIP_STORED to just store the file | |
compression = zipfile.ZIP_DEFLATED | |
# create the zip file first parameter path/name, second mode | |
zf = zipfile.ZipFile("RAWs.zip", mode="w") | |
try: | |
for file_name in tqdm(file_names): | |
# Add file to the zip file | |
# first parameter file to zip, second filename in zip | |
zf.write(path + file_name, file_name, compress_type=compression) | |
except FileNotFoundError: | |
print("An error occurred") | |
finally: | |
# Don't forget to close the file! | |
zf.close() | |
if __name__ == "__main__": | |
containing_dir = "xxx/" | |
with open("yyy.txt", "r") as f: | |
file_names = [l.strip()+".bin" for l in f.readlines()] | |
compress(containing_dir, file_names) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment