Python iterate over path tree.
安装
你可以通过 pypi 安装
pip install -U iterdir
使用
用作模块
from iterdir import iterdir
用作命令
提供一个命令行工具,用于导出目录树
$ iterdir -h
usage: iterdir [-h] [-m MIN_DEPTH] [-M MAX_DEPTH]
[-k [{inode,name,path,relpath,is_dir,stat,stat_info} ...]]
[-s SELECT] [-se] [-o OUTPUT_FILE]
[-hs [{shake_256,blake2b,blake2s,sha512_224,sha224,sha3_384,sha512,ripemd160,sm3,md5-sha1,sha3_256,sha3_224,sha256,sha1,sha384,sha3_512,shake_128,sha512_256,md5,crc32} ...]]
[-dfs] [-fl] [-v]
[path]
目录树信息遍历导出
positional arguments:
path 文件夹路径,默认为当前工作目录
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 时不限
-k [{inode,name,path,relpath,is_dir,stat,stat_info} ...], --keys [{inode,name,path,relpath,is_dir,stat,stat_info} ...]
选择输出的 key,默认输出所有可选值
-s SELECT, --select SELECT
对路径进行筛选,提供一个表达式(会注入一个变量 entry,类型是 iterdir.DirEntry)或函数(会传入一个参数,类型是 iterdir.DirEntry)
-se, --select-exec 对 -s/--select 传入的代码用 exec 运行,其中必须存在名为 select 的函数。否则,视为表达式或 lambda 函数
-o OUTPUT_FILE, --output-file OUTPUT_FILE
保存到文件,此时命令行会输出进度条,根据扩展名来决定输出格式
- *.csv 输出一个 csv,第 1 行为表头,以后每行输出一条数据
- *.json 输出一个 JSON Object 的列表
- * 每行输出一条 JSON Object
-hs [{shake_256,blake2b,blake2s,sha512_224,sha224,sha3_384,sha512,ripemd160,sm3,md5-sha1,sha3_256,sha3_224,sha256,sha1,sha384,sha3_512,shake_128,sha512_256,md5,crc32} ...], --hashes [{shake_256,blake2b,blake2s,sha512_224,sha224,sha3_384,sha512,ripemd160,sm3,md5-sha1,sha3_256,sha3_224,sha256,sha1,sha384,sha3_512,shake_128,sha512_256,md5,crc32} ...]
计算文件的哈希值,可以选择多个算法
-dfs, --depth-first 使用深度优先搜索,否则使用广度优先
-fl, --follow-symlinks
跟进符号连接,否则会把符号链接视为文件,即使它指向目录
-v, --version 输出版本号
Metadata
Release files for iterdir 0.0.10.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iterdir-0.0.10.1.tar.gz | 9.0 kB | Without provenance | Details for iterdir-0.0.10.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iterdir-0.0.10.1-py3-none-any.whl | Python 3 | none | any | Details for iterdir-0.0.10.1-py3-none-any.whl |
Total release size: 20.1 kB
Release files / iterdir-0.0.10.1.tar.gz
| Download URL | iterdir-0.0.10.1.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c7cb028f60043d6707549e995113946394bc9570e3dea001e808343fc2a6753
|
|
BLAKE2b-256 checksum How to use checksums |
389f054abadb6a37ca162d7616425222acc4c24a0db6cc74f85baf80b2b51758
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.13.5 Darwin/25.0.0
|
Release files / iterdir-0.0.10.1-py3-none-any.whl
| Download URL | iterdir-0.0.10.1-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8cdfc0a3823476db956991391ae4d0d81abd45e3ed93d7f06eec3a77a361df9b
|
|
BLAKE2b-256 checksum How to use checksums |
43afb8435219544b7b82b0b2c3945514ff51a545c660c2fb8a0a759d8c1c7650
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.13.5 Darwin/25.0.0
|
Security for iterdir 0.0.10.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.