zip foldersΒΆ

This example demonstrates zipping the subfolders of a parent directory.

Import lsframe, import shutil for creating the zip files, and import os for defining paths,

import lsframe as ls
import shutil
import os

Set the path to a parent directory full of folders you would like to zip,

path = "../path/to/parent/directory"

Create the start object, create a directory_map, and make a frame from the directory_map with depth of 1 consisting only of folders. This means the names column of the frame consists of the names of the folders that reside at the given path,

lsobject = ls.start(directory=path)
lsobject.map_directory()
lsobject.map_to_frame(depth=1, kind="folders")

Scan through the names of the folders collected in the frame and create zip files of the contents,

[
    shutil.make_archive(os.path.join(path, name), "zip", os.path.join(path, name))
    for name in lsobject.frame.name
]

Total running time of the script: ( 0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery