mate_tool_box_zip#

Provide zip related functions.

pathlib_mate.mate_tool_box_zip.rand_str(length)[source]#
Return type:

str

class pathlib_mate.mate_tool_box_zip.ToolBoxZip[source]#

Provide zip related functions.

make_zip_archive(dst=None, filters=<function all_true>, compress=True, overwrite=False, makedirs=False, include_dir=True, verbose=False)[source]#

Make a zip archive of a directory or a file.

Parameters:
  • dst (Optional[Union[Path, str]]) – output file path. if not given, will be automatically assigned.

  • filters (Callable) – custom path filter. By default it allows any file.

  • compress (bool) – compress or not.

  • overwrite – overwrite exists or not.

  • makedirs (bool) – if True, automatically create the parent dir if not exists

  • include_dir (bool) – if True, then you will see the source dir when you unzip it. It only apply when zipping a directory

  • verbose (bool) – display log or not.

backup(dst=None, ignore=None, ignore_ext=None, ignore_pattern=None, ignore_size_smaller_than=None, ignore_size_larger_than=None, case_sensitive=False, include_dir=True, verbose=True)[source]#

Create a compressed zip archive backup for a directory.

Parameters:
  • dst (Optional[Union[Path, str]]) – the output file path.

  • ignore (Optional[List[str]]) – file or directory defined in this list will be ignored.

  • ignore_ext (Optional[List[str]]) – file with extensions defined in this list will be ignored.

  • ignore_pattern (Optional[List[str]]) – any file or directory that contains this pattern will be ignored.

  • ignore_size_smaller_than (int) – any file size smaller than this will be ignored.

  • ignore_size_larger_than (int) – any file size larger than this will be ignored.

  • case_sensitive (bool) – if True, the ignore rules are case sensitive

  • include_dir (bool) – if True, then you will see the source dir when you unzip it. It only apply when zipping a directory

  • verbose (bool) – display log or not.

中文文档

为一个目录创建一个备份压缩包。可以通过过滤器选择你要备份的文件。