发一个显示目录树的小程序(Python)

软件和网站开发以及相关技术探讨
回复
rainy14f
帖子: 23
注册时间: 2006-07-27 0:30
联系:

发一个显示目录树的小程序(Python)

#1

帖子 rainy14f » 2006-08-01 21:55

刚学着用LINUX和PYTHON,写个小程序,用来显示目录树,挺方便的:D
http://shaofan.blogjava.net/Files/shaofan/dtree.rar
图片
我爱好Java,正在学习Python和Linux,很高兴和你交朋友!我的BLOG是http://shao-fan.com/blog
头像
FFFrog
帖子: 621
注册时间: 2006-05-12 23:28
来自: 江西乐平
联系:

#2

帖子 FFFrog » 2006-08-07 11:30

谢谢!是跟Windows下tree的功能类似的程序吧?正好需要这个功能。

不过,弱弱的问一句,Python程序要怎样运行呢?我完全不了解Python的…… :oops:
rainy14f
帖子: 23
注册时间: 2006-07-27 0:30
联系:

#3

帖子 rainy14f » 2006-08-10 8:18

Ubuntu是自动安装了Python的吧,那就直接把程序放到目录里,运行就可以啦 ./dtree.py,要想方便的话拷到/usr/bin里,随时都可以用了
我爱好Java,正在学习Python和Linux,很高兴和你交朋友!我的BLOG是http://shao-fan.com/blog
头像
FFFrog
帖子: 621
注册时间: 2006-05-12 23:28
来自: 江西乐平
联系:

#4

帖子 FFFrog » 2006-08-10 9:26

谢谢!已经用上了。上次记得好像也是这样的操作但不知为何那个dtree.py进程僵死了。总之现在可以正常使用了,呵呵。很实用的功能。:D

不知道除了加目录名参数之外,还有没有别的用法呢?
rainy14f
帖子: 23
注册时间: 2006-07-27 0:30
联系:

#5

帖子 rainy14f » 2006-08-18 7:39

没有啦,程序很短的,你自己可以改来用啊,加什么功能都可以
我爱好Java,正在学习Python和Linux,很高兴和你交朋友!我的BLOG是http://shao-fan.com/blog
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#6

帖子 eexpress » 2006-08-18 10:08

可以用bash掉zenity试试。更加符合gnome风格了。
本身就是gtk+带的嘛。 :lol:
● 鸣学
闪梦
帖子: 7
注册时间: 2006-06-21 9:37

#7

帖子 闪梦 » 2006-10-20 11:33

:oops: :oops: :oops:

看8懂~~~偶刚开始。。。。。。。。
头像
goldfox_79
帖子: 2004
注册时间: 2005-10-16 8:26
来自: 地球

#8

帖子 goldfox_79 » 2006-11-09 23:31

有意思,刚刚开始看python的教程
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

#9

帖子 aBiNg » 2006-11-29 18:49

linux下没有tree命令么? :roll:

~$sudo apt-get install tree -y --force-yes
~$cd howto
~/howto$tree

代码: 全选

.
|-- C_C++
|   |-- A_Quick_Intro_C++.pdf
|   |-- An_Overview_of_the_C++.pdf
|   |-- C_programming.pdf
|   |-- C程序设计
|   |   |-- C++_guide.PDF
|   |   |-- algorithm.PDF
|   |   |-- appendix_A.pdf
|   |   |-- appendix_B.PDF
|   |   |-- array.PDF
|   |   |-- control_statement.PDF
|   |   |-- data_type.PDF
|   |   |-- function.PDF
|   |   |-- input_and_output.PDF
|   |   |-- pointer.PDF
|   |   |-- practical_tips.PDF
|   |   `-- structural_and_shared.PDF
|   |-- EssentialC.pdf
|   |-- O' Reilly - Practical C Programming 3rd Edition.pdf
|   |-- The C++ Programming Language 3rd Ed.pdf
|   |-- The C++ Standard Library.pdf
|   `-- The_C_programming_Language
|       |-- appa.html
|       |-- appb.html
|       |-- appc.html
|       |-- chapter1.html
|       |-- chapter2.html
|       |-- chapter3.html
|       |-- chapter4.html
|       |-- chapter5.html
|       |-- chapter6.html
|       |-- chapter7.html
|       |-- chapter8.html
|       |-- images
|       |   |-- pic11.gif
|       |   |-- pic41.gif
|       |   |-- pic51.gif
|       |   |-- pic510.gif
|       |   |-- pic511.gif
|       |   |-- pic512.gif
|       |   |-- pic52.gif
|       |   |-- pic53.gif
|       |   |-- pic54.gif
|       |   |-- pic55.gif
|       |   |-- pic56.gif
|       |   |-- pic57.gif
|       |   |-- pic58.gif
|       |   |-- pic59.gif
|       |   |-- pic61.gif
|       |   |-- pic62.gif
|       |   |-- pic63.gif
|       |   |-- pic64.gif
|       |   |-- pic81.gif
|       |   `-- pic82.gif
|       |-- index.html
|       |-- intro.html
|       |-- preface.html
|       `-- preface1.html
|-- Linux
|   |-- Aviation_HOWTO.pdf
|   |-- Debian GNU Linux Bible.pdf
|   |-- Intro_Linux.pdf
|   |-- Linux_Dic.pdf
|   |-- Linux_Kernel_2.4_Internals.pdf
|   |-- Linux_Network_Admin_Guide.pdf
|   |-- Linux_Tips_and_Tricks.pdf
|   |-- Linux命令参考手册.pdf
|   |-- Linux常见问题解答集中版.pdf
|   |-- Moving_to_Ubuntu_Linux.chm
|   |-- O'REILLY Learning the Unix OS.chm
|   |-- Python_regexp.pdf
|   |-- Teach_Yourself_Linux_in_24_Hours.pdf
|   |-- UBUNTU服务器指南.pdf
|   |-- Ubuntu_hacks.chm
|   |-- Unix_regexp.pdf
|   |-- debian-faq.en.pdf
|   `-- sed&awk.pdf
|-- Python_perl_shell
|   |-- ABS_Guide_cn.pdf
|   |-- Advanced Perl Programming.pdf
|   |-- Advanced_Bash_Scripting_Guide.pdf
|   |-- Dive_Into_Python.chm
|   |-- O'Reilly Learning Perl.pdf
|   |-- TIPython
|   |   |-- code
|   |   |   |-- SanityCheck.py
|   |   |   |-- c01
|   |   |   |   |-- BorgSingleton.py
|   |   |   |   |-- NewSingleton.py
|   |   |   |   |-- Simple2.py
|   |   |   |   |-- SimpleClass.py
|   |   |   |   |-- SimpleClass.pyc
|   |   |   |   |-- SingletonDecorator.py
|   |   |   |   |-- SingletonMetaClass.py
|   |   |   |   |-- SingletonPattern.py
|   |   |   |   |-- differentReturns.py
|   |   |   |   |-- if.py
|   |   |   |   |-- list.py
|   |   |   |   |-- myFunction.py
|   |   |   |   |-- stringFormatting.py
|   |   |   |   |-- strings.py
|   |   |   |   |-- sum.py
|   |   |   |   `-- tmp
|   |   |   |-- c03
|   |   |   |   |-- TemplateMethod.py
|   |   |   |   `-- tmp
|   |   |   |-- c04
|   |   |   |   |-- ProxyDemo.py
|   |   |   |   |-- ProxyDemo2.py
|   |   |   |   |-- StateDemo.py
|   |   |   |   |-- mouse
|   |   |   |   |   |-- MouseAction.py
|   |   |   |   |   |-- MouseAction.pyc
|   |   |   |   |   |-- MouseMoves.txt
|   |   |   |   |   `-- tmp
|   |   |   |   |-- mousetrap1
|   |   |   |   |   |-- MouseTrapTest.py
|   |   |   |   |   `-- tmp
|   |   |   |   |-- mousetrap2
|   |   |   |   |   |-- MouseTrap2Test.py
|   |   |   |   |   `-- tmp
|   |   |   |   |-- statemachine
|   |   |   |   |   |-- State.py
|   |   |   |   |   |-- State.pyc
|   |   |   |   |   |-- StateMachine.py
|   |   |   |   |   |-- StateMachine.pyc
|   |   |   |   |   `-- tmp
|   |   |   |   `-- tmp
|   |   |   |-- c05
|   |   |   |   |-- Games.py
|   |   |   |   |-- Games2.py
|   |   |   |   |-- shapefact1
|   |   |   |   |   |-- ShapeFactory1.py
|   |   |   |   |   `-- tmp
|   |   |   |   |-- shapefact2
|   |   |   |   |   |-- ShapeFactory2.py
|   |   |   |   |   `-- tmp
|   |   |   |   `-- tmp
|   |   |   |-- c06
|   |   |   |   |-- ChainOfResponsibility.py
|   |   |   |   |-- CommandPattern.py
|   |   |   |   |-- StrategyPattern.py
|   |   |   |   `-- tmp
|   |   |   |-- c07
|   |   |   |   |-- Adapter.py
|   |   |   |   `-- tmp
|   |   |   |-- c10
|   |   |   |   |-- BoxObserver.py
|   |   |   |   |-- BoxObserver.rsrc.py
|   |   |   |   |-- ObservedFlower.py
|   |   |   |   `-- tmp
|   |   |   |-- c11
|   |   |   |   |-- FlowerVisitors.py
|   |   |   |   |-- PaperScissorsRock.py
|   |   |   |   |-- PaperScissorsRock2.py
|   |   |   |   `-- tmp
|   |   |   |-- cX
|   |   |   |   `-- decorator
|   |   |   |       |-- alldecorators
|   |   |   |       |   |-- CoffeeShop.py
|   |   |   |       |   `-- tmp
|   |   |   |       |-- compromise
|   |   |   |       |   |-- CoffeeShop.py
|   |   |   |       |   `-- tmp
|   |   |   |       `-- nodecorators
|   |   |   |           |-- CoffeeShop.py
|   |   |   |           `-- tmp
|   |   |   `-- util
|   |   |       |-- Observer.py
|   |   |       |-- Observer.pyc
|   |   |       |-- Synchronization.py
|   |   |       |-- Synchronization.pyc
|   |   |       |-- TestSynchronization.py
|   |   |       `-- tmp
|   |   `-- html
|   |       |-- Contents.htm
|   |       |-- DocIdx.htm
|   |       |-- FDocIdx.htm
|   |       |-- FramCont.htm
|   |       |-- FrontMtr.htm
|   |       |-- Index.htm
|   |       |-- IndexXTOC.htm
|   |       |-- Intro.htm
|   |       |-- Preface.htm
|   |       |-- Sect01.htm
|   |       |-- Sect02.htm
|   |       |-- Sect03.htm
|   |       |-- Sect04.htm
|   |       |-- Sect05.htm
|   |       |-- Sect06.htm
|   |       |-- Sect07.htm
|   |       |-- Sect08.htm
|   |       |-- Sect09.htm
|   |       |-- Sect10.htm
|   |       |-- Sect11.htm
|   |       |-- Sect12.htm
|   |       |-- Sect13.htm
|   |       |-- Sect14.htm
|   |       |-- Sect15.htm
|   |       |-- SimpCont.htm
|   |       |-- TIPyth00.gif
|   |       |-- TIPyth01.gif
|   |       |-- TIPyth02.gif
|   |       |-- TIPyth03.gif
|   |       |-- TIPyth04.gif
|   |       |-- TIPyth05.gif
|   |       |-- TIPyth06.gif
|   |       |-- TIPyth07.gif
|   |       |-- TIPyth08.gif
|   |       |-- TIPyth09.gif
|   |       |-- TIPython.err
|   |       |-- TIPython.rtf
|   |       `-- mindview.gif
|   |-- perl.pdf
|   `-- thinkCSpy.pdf
`-- man
    |-- grep
    |-- grep~
    |-- regular_expr
    |-- regular_expr~
    `-- sed

30 directories, 191 files
~/howto$tree --help

代码: 全选

usage: tree [-adfgilnpqrstuxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
        [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
        [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
        [<directory list>]
    -a          All files are listed.
    -d          List directories only.
    -l          Follow symbolic links like directories.
    -f          Print the full path prefix for each file.
    -i          Don't print indentation lines.
    -q          Print non-printable characters as '?'.
    -N          Print non-printable characters as is.
    -p          Print the protections for each file.
    -u          Displays file owner or UID number.
    -g          Displays file group owner or GID number.
    -s          Print the size in bytes of each file.
    -D          Print the date of last modification.
    -F          Appends '/', '=', '*', or '|' as per ls -F.
    -r          Sort files in reverse alphanumeric order.
    -t          Sort files by last modification time.
    -x          Stay on current filesystem only.
    -L level    Descend only level directories deep.
    -A          Print ANSI lines graphic indentation lines.
    -S          Print with ASCII graphics indentation lines.
    -n          Turn colorization off always (-C overrides).
    -C          Turn colorization on always.
    -P pattern  List only those files that match the pattern given.
    -I pattern  Do not list files that match the given pattern.
    -H baseHREF Prints out HTML format with baseHREF as top directory.
    -T string   Replace the default HTML title and H1 header with string.
    -R          Rerun tree when max dir level reached.
    -o file     Output to file instead of stdout.
    --inodes    Print inode number of each file.
    --device    Print device ID number to which each file belongs.
    --noreport  Turn off file/directory count at end of tree listing.
    --nolinks   Turn off hyperlinks in HTML output.
    --dirsfirst List directories before files.
    --charset X Use charset X for HTML and indentation line output.
头像
FFFrog
帖子: 621
注册时间: 2006-05-12 23:28
来自: 江西乐平
联系:

#10

帖子 FFFrog » 2006-12-10 23:26

:shock: cool~ :D
回复