mate_path_filters#

Provide friendly path filter API.

class pathlib_mate.mate_path_filters.PathFilters[source]#

Provide friendly path filter API.

assert_is_file_and_exists()[source]#

Assert it is a directory and exists in file system.

assert_is_dir_and_exists()[source]#

Assert it is a directory and exists in file system.

assert_exists()[source]#

Assert it exists.

select(filters=<function all_true>, recursive=True)[source]#

Select path by criterion.

Parameters:
  • filters (Callable) – a lambda function that take a Path as input, return boolean as a output.

  • recursive (bool) – include files in sub-folder or not.

Return type:

Iterable[Path]

中文文档

根据filters中定义的条件选择路径.

select_file(filters=<function all_true>, recursive=True)[source]#

Select file path by criterion.

Return type:

Iterable[Path]

中文文档

根据 filters 中定义的条件选择文件.

select_dir(filters=<function all_true>, recursive=True)[source]#

Select dir path by criterion.

Return type:

Iterable[Path]

中文文档

根据 filters 中定义的条件选择文件夹.

property n_file#

Count how many files in this directory. Including file in sub folder.

Return type:

int

property n_dir#

Count how many folders in this directory. Including folder in sub folder.

Return type:

int

property n_subfile#

Count how many files in this directory (doesn’t include files in sub folders).

Return type:

int

property n_subdir#

Count how many folders in this directory (doesn’t include folder in sub folders).

Return type:

int

select_by_ext(ext, recursive=True)[source]#

Select file path by extension.

Return type:

Iterable[Path]

中文文档

选择与预定义的若干个扩展名匹配的文件.

select_by_pattern_in_fname(pattern, recursive=True, case_sensitive=False)[source]#

Select file path by text pattern in file name.

Return type:

Iterable[Path]

中文文档

选择文件名中包含指定子字符串的文件.

select_by_pattern_in_abspath(pattern, recursive=True, case_sensitive=False)[source]#

Select file path by text pattern in absolute path.

Return type:

Iterable[Path]

中文文档

选择绝对路径中包含指定子字符串的文件.

select_by_size(min_size=0, max_size=1099511627776, recursive=True)[source]#

Select file path by size.

Return type:

Iterable[Path]

中文文档

选择所有文件大小在一定范围内的文件.

select_by_mtime(min_time=0, max_time=4102444800.0, recursive=True)[source]#

Select file path by modify time.

Parameters:
  • min_time (Union[int, float]) – lower bound timestamp

  • max_time (Union[int, float]) – upper bound timestamp

Return type:

Iterable[Path]

中文文档

选择所有 pathlib_mate.pathlib2.Path.mtime 在一定范围内的文件.

select_by_atime(min_time=0, max_time=4102444800.0, recursive=True)[source]#

Select file path by access time.

Parameters:
  • min_time (Union[int, float]) – lower bound timestamp

  • max_time (Union[int, float]) – upper bound timestamp

Return type:

Iterable[Path]

中文文档

选择所有 pathlib_mate.pathlib2.Path.atime 在一定范围内的文件.

select_by_ctime(min_time=0, max_time=4102444800.0, recursive=True)[source]#

Select file path by create time.

Parameters:
  • min_time (Union[int, float]) – lower bound timestamp

  • max_time (Union[int, float]) – upper bound timestamp

Return type:

Iterable[Path]

中文文档

选择所有 pathlib_mate.pathlib2.Path.ctime 在一定范围内的文件.

select_image(recursive=True)[source]#

Select image file.

Return type:

Iterable[Path]

select_audio(recursive=True)[source]#

Select audio file.

Return type:

Iterable[Path]

select_video(recursive=True)[source]#

Select video file.

Return type:

Iterable[Path]

select_word(recursive=True)[source]#

Select Microsoft Word file.

Return type:

Iterable[Path]

select_excel(recursive=True)[source]#

Select Microsoft Excel file.

Return type:

Iterable[Path]

select_archive(recursive=True)[source]#

Select compressed archive file.

Return type:

Iterable[Path]

static sort_by_abspath(p_list, reverse=False)#

Sort list of Path by absolute path.

Params p_list:

list of Path

Params reverse:

if False, return in descending order

static sort_by_fname(p_list, reverse=False)#

Sort list of Path by file name.

Params p_list:

list of Path

Params reverse:

if False, return in descending order

static sort_by_ext(p_list, reverse=False)#

Sort list of Path by extension.

Params p_list:

list of Path

Params reverse:

if False, return in descending order

static sort_by_size(p_list, reverse=False)#

Sort list of Path by file size.

Params p_list:

list of Path

Params reverse:

if False, return in descending order

static sort_by_mtime(p_list, reverse=False)#

Sort list of Path by modify time.

Params p_list:

list of Path

Params reverse:

if False, return in descending order

static sort_by_atime(p_list, reverse=False)#

Sort list of Path by access time.

Params p_list:

list of Path

Params reverse:

if False, return in descending order

static sort_by_ctime(p_list, reverse=False)#

Sort list of Path by create time.

Params p_list:

list of Path

Params reverse:

if False, return in descending order

static sort_by_md5(p_list, reverse=False)#

Sort list of Path by md5.

Params p_list:

list of Path

Params reverse:

if False, return in descending order

property dirsize#

Return total file size (include sub folder). Symlink doesn’t count.

Return type:

int