Skynet

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

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks
          迭代
          python ./demo.py /xx/google/g2/
          #coding=UTF-8
          import os
          import re
          import sys 



          dir
          ='/home/liukaiyi/桌面/py/'
          todir
          ='/home/liukaiyi/桌面/test/'
          if  os.path.isdir(dir)==False:
              os.mkdir(dir)
          if  os.path.isdir(todir)==False:
              os.mkdir(todir)

          usedir
          =sys.argv[1]
          dir
          +=usedir+'/'
          todir
          +=usedir+'/'

          mk_dir 
          = '/'
          for tdir in dir.split('/'):
              
          if tdir=="":
                  
          continue
              mk_dir 
          += tdir+'/'
              
          if  os.path.isdir(mk_dir)==False:
                  os.mkdir(mk_dir)

          mk_todir 
          = '/'
          for tdir in todir.split('/'):
              
          if tdir=="":
                  
          continue
              mk_todir 
          += tdir+"/"
              
          if  os.path.isdir(mk_todir)==False:
                  os.mkdir(mk_todir)


          def action(path,tpath,file):
              
          print '>>>>>>>>>>>>>>'+path,tpath,file
                  
          def listAll(rootpath):
              tpath 
          = todir+re.sub(dir,"",rootpath)
              
          if  os.path.isdir(tpath)==False:
                  os.mkdir(tpath)
                  
          print 'mkdir>'+tpath

              
          for file in os.listdir(rootpath):
                  
          if os.path.isfile(rootpath+file):
                      filename 
          = ".".join(file.split('.')[0:-1])
                      bool 
          = False
                      
          for tfile in os.listdir(tpath) :
                          
          if ".".join(tfile.split('.')[0:-1]) == filename :
                              bool
          =True
                      
          if bool==False:
                          action(rootpath,tpath,file)
              
                  
          for file in os.listdir(rootpath):
                  path 
          = rootpath+file+'/'
                      
          if os.path.isdir(path):
                      listAll(path)

          listAll(dir)


          整理 www.aygfsteel.com/Good-Game
          posted on 2008-11-26 22:55 劉凱毅 閱讀(168) 評論(0)  編輯  收藏 所屬分類: python
          主站蜘蛛池模板: 沂南县| 会昌县| 新巴尔虎右旗| 徐闻县| 马尔康县| 江山市| 肇东市| 玉门市| 嘉义市| 龙泉市| 崇明县| 永德县| 罗源县| 桐柏县| 克东县| 铜鼓县| 绿春县| 会昌县| 满洲里市| 沙雅县| 定陶县| 祁东县| 新郑市| 梓潼县| 东海县| 泽州县| 荆门市| 临城县| 儋州市| 兴安县| 张北县| 新巴尔虎右旗| 石台县| 斗六市| 右玉县| 普兰县| 永州市| 宁武县| 镇安县| 睢宁县| 阿瓦提县|