确定当前(或指定)目录树中的最大深度和路径长度。
deepest的Python项目详细描述
最深
“There are older and fouler things than Orcs in the deep places of the world.”
— Gandalf, from “The Lord of the Rings: The Fellowship of the Ring”, by J.R.R. Tolkien
deep-使用的跨平台(和跨语言)命令行实用程序 确定当前(或指定的)目录树的最大深度。
在Python和C++口味中都可用(通过^ {A3}库)。
基本原理
- 需要一种方法来确定项目与 8-由ISO-9660定义的子目录限制。
- 需要一种方法来确定距离MAX_PATH目录有多近
正在获取。
- MAX_PATH在Windows:3上定义为驱动器的260个字符 (C:\),1表示结尾的NULL字符,256 对于中间目录、反斜线、文件名和扩展名。
- “是的,但是……为什么是Python?“
- 它的原型更快。(偏见…我只是更熟悉它。)
- 这给了我一个尝试ShedSkin的借口。:-)
要求
- python>;=2.7、3.2、3.3、3.4、3.5、3.6
- shedskin=0.9.3,0.9.4-可选
- g++>;=4.6.2或clang++>;=3.2-可选
- mingw/msys(2012-04-26目录)-可选
安装
python(用户):
pip install deepest
python(开发人员):
git clone git@github.com:markgollnick/deepest.git cd deepest python setup.py build install # Alternatively... make python pip install dist/deepest-*.tar.gz
^ {STR 1 } $C++< /强>:
下载并安装ShedSkin(instructions)。
运行以下命令:
./3to2 # Make some minor adjustments for ShedSkin compatibility cd deepest # This is the dir INSIDE the project's root dir shedskin deepest.py make # Alternatively, from the project's root dir... make cpp
使用量
python:
安装后,您可以将其用作脚本…
$ deepest . breadth of dirs examined longest pathname deepest directory 13 58 7 longest file: ./workspace/dwarves/digging/deep/deeper/deepest/balrog.log deepest path: ./workspace/some/really/long/directory/chain/here
…或者,您可以将其用作库:
>>> import deepest >>> deepest.get_depth('c:\\workspace') ('c:\\workspace\\some\\really\\long\\directory\\chain\\here', 7) >>> deepest.get_length('c:\\workspace') ('c:\\workspace\\dwarves\\digging\\deep\\deeper\\deepest\\balrog.log', 59)
^ {STR 1 } $c++:< /强>
编译完成后,它是python脚本的一种(特别是更快的)替代方案:
$ deepest c:\\workspace breadth of dirs examined longest pathname deepest directory 13 59 7 longest file: c:\workspace\dwarves\digging\deep\deeper\deepest\balrog.log deepest path: c:\workspace\some\really\long\directory\chain\here
速度
在一个包含5000多个目录、最大深度为13的项目中, Python和C++版本(用CLAN-503.0.40编译)是针对每个 其他。这两个版本都在2013年底的MacBookPro上运行了三次。
这些是平均结果:
$ time deepest # Python script ... real 0m0.423s user 0m0.244s sys 0m0.160s $ time deepest # C++ binary ... real 0m0.169s user 0m0.063s sys 0m0.101s在实际观察中,使用编译后的C++版本可以在任何地方获得您。 从10%到高达60%的速度提升。:-)
许可证
Boost软件许可证,1.0版:<;http://www.boost.org/LICENSE_1_0.txt>;