• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 87  文章 - 279  trackbacks - 0
            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 219046
            • 排名 - 118

            最新評論

            閱讀排行榜

            評論排行榜

            弱弱的寫了一下,可以自用-_-
              1 #!/usr/bin/env python
              2 
              3 import os
              4 import os.path
              5 import re
              6 import sys
              7 
              8 re_sp = re.compile("/")
              9 max_level = 0x7FFFFFFF
             10 
             11 
             12 def get_dirname(path) :
             13     """
             14     get the dirname by a path
             15     """
             16     global re_sp
             17 
             18     path = os.path.realpath(path)
             19     lst_ret = re_sp.split(path)
             20     if 0 == len(lst_ret) :
             21         return ""
             22     return lst_ret[len(lst_ret)-1]
             23 
             24 
             25 def get_startmark(path, lvl) :
             26     """
             27     get the startmark which will be displayed first
             28     """
             29     global max_level
             30 
             31     new_str = ""
             32     for i in range(lvl) :
             33         new_str += '|'
             34 
             35     if True == os.path.isdir(path) :
             36         if len(os.listdir(path)) > 0 and lvl == max_level:
             37             new_str += "+"
             38         else :
             39             new_str += "-"
             40         for i in range(lvl) :
             41             new_str += ' '
             42     else :
             43         new_str += '|'
             44         for i in range(lvl) :
             45             new_str += ' '
             46     
             47     return new_str
             48 
             49 
             50 def dfs_dir(path, lvl) :
             51     """
             52     deep first search the path
             53     """
             54     global max_level
             55 
             56     new_str = get_startmark(path, lvl)
             57     print "%s%s" % (new_str, get_dirname(path)),
             58 
             59     #check file type
             60     if True == os.path.islink(path) :
             61         print "%s" % "[L]",
             62     if True == os.path.ismount(path) :
             63         print "%s" % "[M]",
             64     if False == os.path.isdir(path) :
             65         print "[%d]" % os.path.getsize(path)    
             66     else :
             67         print ""
             68 
             69     if False == os.path.isdir(path) :
             70         return
             71 
             72     if lvl == max_level :
             73         return
             74 
             75     files = os.listdir(path)
             76     for each_file in files :
             77         new_path = "%s/%s" % (path, each_file)
             78         dfs_dir(new_path, lvl+1)
             79 
             80 
             81 def pytree() :
             82     """
             83     the main function to run
             84     """
             85     global max_level
             86 
             87     argvs = sys.argv
             88     
             89     if 0 == len(argvs) % 2 :
             90         print "Argvs invalid!"
             91         sys.exit(-1)
             92     else :
             93         cur_path = ""
             94 
             95         for tmp_str in argvs :
             96             if tmp_str.startswith("-") :
             97                 if "-i" == tmp_str :
             98                     idx = argvs.index(tmp_str)
             99                     max_level = int(argvs[idx+1])
            100                 if "-p" == tmp_str:
            101                     idx = argvs.index(tmp_str)
            102                     cur_path = os.path.realpath(argvs[idx+1])
            103 
            104         if "" == cur_path :
            105             cur_path = os.getcwd()
            106 
            107         if False == os.path.isdir(cur_path) :
            108             print "Argvs invalid : path not exits!"
            109         else :
            110             print "List Dir : %s" % cur_path
            111             dfs_dir(cur_path, 0)
            112 
            113     
            114 
            115 
            116 if __name__ == "__main__" :
            117     pytree()
            118 


            posted on 2009-03-29 19:56 閱讀(282) 評論(0)  編輯 收藏 引用 所屬分類: Python

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久被窝电影亚洲爽爽爽| 欧美日韩中文字幕久久久不卡| 色综合久久久久无码专区| 国内精品久久久久影院日本| 99久久伊人精品综合观看| 久久人人爽人人爽人人片AV不| 国产一区二区精品久久| 日韩电影久久久被窝网| 日本免费久久久久久久网站| 亚洲AV无码一区东京热久久| 久久露脸国产精品| 97r久久精品国产99国产精| 亚洲精品无码久久不卡| 国产免费久久久久久无码| 国内精品伊人久久久久av一坑| 亚洲欧美国产精品专区久久| 99久久综合狠狠综合久久| 国内精品久久久人妻中文字幕| 国产免费久久精品99re丫y| 国产AV影片久久久久久| 国产一区二区三区久久精品| 久久人妻少妇嫩草AV无码专区| 伊人情人综合成人久久网小说| 久久九九青青国产精品| 伊人久久大香线蕉av不卡 | 久久99国内精品自在现线| 亚洲精品综合久久| 一本色综合久久| 国产精品亚洲综合久久| 亚洲日本va午夜中文字幕久久| 热RE99久久精品国产66热| 久久九色综合九色99伊人| 久久99精品国产99久久6| 国产午夜电影久久| 亚洲国产成人久久精品99| 亚洲国产精品综合久久一线| 99久久做夜夜爱天天做精品| 久久久无码精品亚洲日韩蜜臀浪潮 | 久久精品无码午夜福利理论片| 久久精品国产亚洲av日韩| 99久久婷婷免费国产综合精品|