<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Skynet

    ---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks

    當然使用 shell 一行就能解決!
    不過 需求使用 python 所以
    #coding=UTF-8
    import os  
    import re
    import sys


    #遞歸遍歷指定的目錄  
    #
    param:
    #
        array -- 遞歸寄存數組
    #
        level -- 遞歸的層數,用這個參數來控制打印的縮進  
    #
        path  == 遍歷起始絕對路徑  
    #
    return:
    #
        array 返回 {"type":文件類型(f|d),"path":物理文件路徑name":文件名"exp":文件擴展名,稱,"level":深度}
    #
    參考:http://www.javaeye.com/topic/116670 
    _comms = {'-s':'策略','-p':'查找路徑','-c':'替換命令'}
    _mapSub 
    = ("path""name""exp","type","level")
    _mapSub_re 
    = {} 
    for tmp in _mapSub:
        _mapSub_re[tmp] 
    = re.compile("\$\s*\{\s*"+tmp+"\s*\}")

    def listAll(array, level, path):  
        
    for file in os.listdir(path):
            
    if os.path.isfile(path + "\\" + file):
                fe 
    = file.split(".")
                path 
    = re.sub("\\\\""/", path)
                
    if len(fe)>=2:
                    array.append({_mapSub[
    3]:"f", _mapSub[0]:path, _mapSub[1]:".".join(fe[0:-1]), _mapSub[2]:fe[-1], _mapSub[4]:str(level + 1)})
                
    else:
                    array.append({_mapSub[
    3]:"d", _mapSub[0]:path, _mapSub[1]:file, _mapSub[2]:"", _mapSub[4]:str(level + 1)})
            
    else:
                array.append({_mapSub[
    3]:"d", _mapSub[0]:path, _mapSub[1]:file, _mapSub[2]:"", _mapSub[4]:str(level + 1)})
                listAll(array, level 
    + 1, path + "\\" + file)

    def _main():
        
    if len(sys.argv)==1:
            
    print "請輸入參數  -s 策略    -p 查找路徑  -c 替換命令 "
            
    print ' 如 :listdir.py -p . -s findMp3  -c "ls ${path}/${name}.${exp}" '
            exit(0)
         
        argvs 
    = sys.argv[1:]
        
    #argvs = '-s&findMp3&-p&.&-c&"ls ${path}/${name}.${exp}"'.split("&")
        for tc in _comms.keys():
            
    for i in range(len(argvs)):      
                
    if(argvs[i]==tc):
                    _comms[tc]
    =argvs[i+1]
        
    #
        reLGPath = re.compile("^\s*\\.")
        
    if reLGPath.match(_comms['-p']):
            _comms[
    '-p'= os.path.abspath(_comms['-p'])
        _comms[
    '-p'= re.sub("\\\\","/",_comms['-p'])
        
        
        script 
    = _comms['-s']+'()'
        
    for fmap in eval(script):
            tcomm 
    = _comms['-c']
            
    for tk in _mapSub_re.keys():
                tcomm 
    = _mapSub_re[tk].sub(fmap[tk]+"", tcomm+"")
            
    #print tcomm
            os.system(tcomm)           

    #***********************************************************************************************
    #
     策略  添加
    #
    ***********************************************************************************************

    #查找  mp3 策略 
    def findMp3():
        array 
    = []
        mp3Array 
    = []
        listAll(array, 0, _comms[
    '-p'])
        p 
    = re.compile("[mM][pP]3")
        
    for tmap in array:
            
    # 類型  文件 擴展名 mp3 
            if  tmap[_mapSub[3]] == "f" and p.match(tmap[_mapSub[2]]) :
                    mp3Array.append(tmap)
        
    return mp3Array


    #***********************************************************************************************
    #
     測試代碼   listdir.py -p . -s findMp3  -c "ls ${path}/${name}.${exp}"
    #
     可替換 ${path} ${name}  ${exp} ${level} ${type}
    #
    ***********************************************************************************************
    _main()




    整理 m.tkk7.com/Good-Game
    posted on 2008-11-26 15:19 劉凱毅 閱讀(1382) 評論(0)  編輯  收藏 所屬分類: python
    主站蜘蛛池模板: 四虎永久免费地址在线网站| 免费福利视频导航| 日韩免费一级毛片| 国产精品亚洲专区在线观看 | 巨胸喷奶水视频www免费视频| 国产大片91精品免费观看男同| 四虎必出精品亚洲高清| 在线观看免费人成视频| 国产婷婷综合丁香亚洲欧洲| 一本岛高清v不卡免费一三区| 亚洲女人初试黑人巨高清| 免费看黄视频网站| 亚洲中文字幕久久精品蜜桃 | 久久久久噜噜噜亚洲熟女综合| 麻豆69堂免费视频| 亚洲一区二区视频在线观看| 精品熟女少妇aⅴ免费久久| 亚洲中文久久精品无码ww16| 中文字幕乱码免费看电影| 国精无码欧精品亚洲一区| 无码av免费一区二区三区| 亚洲国产情侣一区二区三区| 97无码免费人妻超级碰碰碰碰| 色五月五月丁香亚洲综合网| 亚洲情a成黄在线观看| 国产成人一区二区三区视频免费| 久久综合亚洲色HEZYO社区| 青娱分类视频精品免费2| 亚洲大码熟女在线观看| 在线亚洲午夜理论AV大片| 免费无码中文字幕A级毛片| 亚洲一线产区二线产区区| 亚洲真人日本在线| 全部免费毛片在线播放| 亚洲无码一区二区三区 | www视频在线观看免费| 亚洲AV香蕉一区区二区三区| 在线观看亚洲成人| 中文字幕乱码免费视频| 一级毛片**免费看试看20分钟| 亚洲国产精品一区|