• <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年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 217801
            • 排名 - 117

            最新評論

            閱讀排行榜

            評論排行榜

            弱弱的寫了一下,可以自用-_-
              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 閱讀(275) 評論(0)  編輯 收藏 引用 所屬分類: Python
            三级韩国一区久久二区综合| 免费观看久久精彩视频| 亚洲va久久久噜噜噜久久天堂| 亚洲午夜无码久久久久| 国产精品99久久久久久董美香| 亚洲v国产v天堂a无码久久| 久久国产精品77777| 色婷婷久久久SWAG精品| 久久国产乱子伦精品免费强| 久久午夜免费视频| 99久久伊人精品综合观看| 久久99精品久久久久久久不卡| 亚洲国产一成久久精品国产成人综合 | 免费精品国产日韩热久久| 久久99精品国产99久久| 亚洲中文精品久久久久久不卡| 国产精品狼人久久久久影院| 久久国产热精品波多野结衣AV| 亚洲七七久久精品中文国产| 99久久国产综合精品网成人影院| 人妻精品久久久久中文字幕69| 精品视频久久久久| 四虎国产精品免费久久久| 久久精品国产亚洲av麻豆色欲| 久久国产劲爆AV内射—百度| 久久天天躁狠狠躁夜夜不卡| 久久天天躁狠狠躁夜夜2020| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 97精品久久天干天天天按摩| 久久人人爽人人人人片av| 亚洲伊人久久成综合人影院 | 伊人久久无码精品中文字幕| 欧美午夜A∨大片久久| 久久夜色精品国产www| 日韩美女18网站久久精品| 理论片午午伦夜理片久久 | 99热精品久久只有精品| 99久久综合国产精品二区| 91久久香蕉国产熟女线看| 精品国产一区二区三区久久蜜臀| 国产成人精品久久综合 |