cornsnake.util_zip
Alias for zip_dir.
def
create_zip(source_dir: str, output_zip_file: str) -> None:
12def create_zip(source_dir: str, output_zip_file: str) -> None: 13 """ 14 Function to create a zip archive from a directory. 15 16 Args: 17 source_dir (str): The path to the source directory to be zipped. 18 output_zip_file (str): The name of the output zip file. 19 20 Returns: 21 None 22 """ 23 if output_zip_file.endswith(".zip"): 24 output_zip_file = output_zip_file[:-4] 25 shutil.make_archive(output_zip_file, "zip", source_dir)
Function to create a zip archive from a directory.
Args: source_dir (str): The path to the source directory to be zipped. output_zip_file (str): The name of the output zip file.
Returns: None
def
create_zip_of_files( files_to_include: list[str], root_dir: str, path_to_output_zipfile: str) -> list[str]:
28def create_zip_of_files( 29 files_to_include: list[str], root_dir: str, path_to_output_zipfile: str 30) -> list[str]: 31 """ 32 Function to create a zip archive from a list of files. 33 34 Args: 35 files_to_include (list[str]): List of filepaths to include. 36 root_dir (str): The root dir to use when deciding the relative path inside the ZIP. 37 path_to_output_zipfile (str): The path to the output zip file. 38 39 Returns: 40 list[str]: List of file paths inside the ZIP. 41 """ 42 if not files_to_include: 43 return [] 44 with zipfile.ZipFile(path_to_output_zipfile, "w") as zip: 45 file_names = [] 46 for file_name in files_to_include: 47 short_file_name = file_name.replace(root_dir, "") 48 file_names.append(short_file_name) 49 zip.write(file_name, short_file_name) 50 return file_names
Function to create a zip archive from a list of files.
Args: files_to_include (list[str]): List of filepaths to include. root_dir (str): The root dir to use when deciding the relative path inside the ZIP. path_to_output_zipfile (str): The path to the output zip file.
Returns: list[str]: List of file paths inside the ZIP.