• 目录过滤python脚本


    1. #coding=utf-8   
    2. import sys,os,os.path  
    3. import pdb  
    4. #只获得第一层子目录,过滤非目录文件   
    5. def getsubdocs(path=None):  
    6.  doclist = []  
    7.  if(os.path.isdir(path)):  
    8.   for item in os.listdir(path):  
    9.    if item != '.svn':  
    10.     if os.path.isdir(path+os.sep+item):  
    11.      doclist.append(item)  
    12.  return doclist  
    13.   
    14. #获得所有层级子目录,过滤非目录文件   
    15. def getallsubdocs(path=None):  
    16.  #pdb.set_trace()   
    17.  doclist = []  
    18.  if(os.path.isdir(path)):  
    19.   if len(os.listdir(path)) > 0:  
    20.    for item in os.listdir(path):  
    21.     if item != '.svn':  
    22.      doclist.extend(getallsubdocs(path+os.sep+item))  
    23.   else:  
    24.    doclist.append(path)  
    25.  return doclist  
    26. #获取所有子目录中,不包括svn相关的目录   
    27. def getalldocs(path=None):  
    28.  doclist = []  
    29.  for root,dirs,files in os.walk(path):  
    30.   if root.find('.svn') < 0:  
    31.    doclist.append(root)   
    32.  return doclist  
    33. if __name__=='__main__':  
    34.  path = raw_input('Enter root path(/*/*/....): ')  
    35.  doclist = getallsubdocs(path)  
    36.  print doclist  
  • 相关阅读:
    大厂Redis高并发场景设计,面试问的都在这!
    POJ1006——中国剩余定理
    HDU3501——欧拉函数裸题
    堆-动态的排序(洛谷1801-黑匣子)
    图中欧拉回路数量
    ip地址
    网络通信概述
    网络通信概述
    软件安装与卸载
    软件安装与卸载
  • 原文地址:https://www.cnblogs.com/SophiaTang/p/2291167.html
Copyright © 2020-2023  润新知