zip_archive

zip_archive(x, file=None, mode='w', root='')

Zip a folder to a file

Parameters

Name Type Description Default
x Union[str, List[str]] Path to the folder to zip or a list of paths to put in a zip file required
file Union[None, str] Path to the output zip file to create. Defaults to a .zip file in the temporary directory. None
mode str Passed on to zipfile.ZipFile. Defaults to ‘w’: write 'w'

Returns

Name Type Description
str a str with the path to the zip file

Examples

>>> from rlike import *
>>> folder = tempdir()
>>> f1 = writeLines(text = 'Hello world. Some more text.', con = file_path(folder, 'fname1.txt'))
>>> f2 = writeLines(text = 'Hello world. Some more text.', con = file_path(folder, 'fname2.txt'))
>>> zip_archive(folder, file = 'xyz.zip')
'xyz.zip'
>>> file_exists([f1, f2, 'xyz.zip'])
[True, True, True]
>>> out = unzip('xyz.zip', path = tempdir())
>>> sorted(basename(out))
['fname1.txt', 'fname2.txt']
>>> zip_archive([f1], file = 'abc.zip', root = dirname(f1))
'abc.zip'
>>> out = unzip('abc.zip', path = tempdir())
>>> basename(out)
['fname1.txt']
>>> clean = file_remove([f1, f2, 'xyz.zip', 'abc.zip'])