Skip to main content

Iterate a directory in a tree-like format.

Project description

Iterate a directory in a tree-like format..

安装

你可以通过 pypi 安装

pip install -U python-treedir

使用

用作模块

提供了一个函数 treedir() 可用于遍历目录树

>>> from treedir import treedir
>>> help(treedir)
Help on function treedir in module treedir:

treedir(top: Union[bytes, str, os.PathLike, ~T] = '.', /, min_depth: int = 0, max_depth: int = -1, onerror: bool | collections.abc.Callable[[OSError], typing.Any] = False, predicate: None | collections.abc.Callable[[~T], None | bool] = None, iterdir: collections.abc.Callable[[typing.Union[bytes, str, os.PathLike, ~T]], ~T] = <built-in function scandir>, is_dir: None | collections.abc.Callable[[~T], bool] = None, _depth: int = 0)
    遍历导出目录树
    
    :param top: 根路径默认为当前目录
    :param min_depth: 最小深度小于 0 时不限参数 `top` 本身的深度为 0它的直接跟随路径的深度是 1以此类推
    :param max_depth: 最大深度小于 0 时不限
    :param onerror: 处理 OSError 异常如果是 True抛出异常如果是 False忽略异常如果是调用以异常为参数调用之
    :param predicate: 调用以筛选遍历得到的路径
    :param iterdir: 迭代罗列目录
    :param is_dir: 判断是不是目录如果为 None则从 iterdir 所得路径上调用 is_dir() 方法
    
    :return: 没有返回值只是在 stdout 输出目录树文本类似 tree 命令

用作命令

提供一个命令行工具,用于导出目录树

$ python -m treedir -h
usage: __main__.py [-h] [-m MIN_DEPTH] [-M MAX_DEPTH] [-s SELECT] [-se] [-fl] [-v] [top]

目录树遍历导出,树形结构

positional arguments:
  top                   根目录路径,默认为当前工作目录

options:
  -h, --help            show this help message and exit
  -m MIN_DEPTH, --min-depth MIN_DEPTH
                        最小深度,默认值 0,小于 0 时不限
  -M MAX_DEPTH, --max-depth MAX_DEPTH
                        最大深度,默认值 -1,小于 0 时不限
  -s SELECT, --select SELECT
                        对路径进行筛选,提供一个表达式(会注入一个变量 path,类型是 pathlib.Path)或函数(会传入一个参数,类型是 pathlib.Path)
  -se, --select-exec    对 -s/--select 传入的代码用 exec 运行,其中必须存在名为 select 的函数。否则,视为表达式或 lambda 函数
  -fl, --follow-symlinks
                        跟进符号连接,否则会把符号链接视为文件,即使它指向目录
  -v, --version         输出版本号

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_treedir-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

python_treedir-0.0.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file python_treedir-0.0.1.tar.gz.

File metadata

  • Download URL: python_treedir-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.8 Darwin/23.5.0

File hashes

Hashes for python_treedir-0.0.1.tar.gz
Algorithm Hash digest
SHA256 33eadea91f8a8cf3c5f46f0d2309184097402490facd9081eafffa48299e48c0
MD5 29ca648837f8f6f2c6f24d1e27b84ea0
BLAKE2b-256 7473e9b66347971e01a3c85f9ecb932bf5908da9967bb26a0631396a31f63d7c

See more details on using hashes here.

File details

Details for the file python_treedir-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: python_treedir-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.8 Darwin/23.5.0

File hashes

Hashes for python_treedir-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd5a09a262cc340baeffed12ab6d0545b0b7ba6829751664844e559f1a035985
MD5 3709eb532b4938d16b6179d5798f7edb
BLAKE2b-256 ed02b0ddb1f84adaaf24e8d430b990b8acfae2d9ef00e7591a62fd314cc7e269

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page