def __dirSearch1(self, _rootCatalog, _ndeep=10): """ 文件夹遍历,结果存放在自定义的目录对象(CatalogList),用于存放一个文件夹包含的所有文件(CatalogItem)对象 :param _rootCatalog: 目录对象(CatalogList) :param _ndeep: 允许的最大递归索引深度 :return: """ if isinstance(_rootCatalog, Catalog.CatalogList): dirPath = _rootCatalog.dirPath() dirlist = [] if os.path.isdir(dirPath) and (dirPath != '/'): dirlist = os.listdir(dirPath) if len(dirlist) <= 0: return False dirHaveRightDoc = False for t_file in dirlist: # print os.path.join(dirPath, t_file) if not os.path.isdir(os.path.join(dirPath, t_file)): if self.isFIleInFilter(t_file): _rootCatalog.addItem(Catalog.CatalogItem(t_file)) dirHaveRightDoc = dirHaveRightDoc or True else: t_childrenlist = Catalog.CatalogList(os.path.join(dirPath, t_file)) t_catalogItem = Catalog.CatalogItem(t_file, _children=t_childrenlist) _rootCatalog.addItem(t_catalogItem) if _ndeep >= 0: a = self.__dirSearch1(t_childrenlist, _ndeep=_ndeep-1) dirHaveRightDoc = dirHaveRightDoc or a return dirHaveRightDoc
def GetCatalogTree(self, dirPath): """ 使用__dirSearch1()方法搜索目录,产生CatalogList对象,存放独有成员self.catalogTree :param dirPath: :return: """ self.catalogTree = Catalog.CatalogList(dirPath) self.__dirSearch1(self.catalogTree) return self.catalogTree
def SetCatalogObj(self, dirPath, _ndeep=10): """ 使用__dirSearch()方法搜索目录,并返回结果 :param dirPath: :param _ndeep:索引深度 :return:self.__CatalogObj:目录对象CatalogList """ self.__CatalogObj = Catalog.CatalogList(dirPath) self.__dirSearch(self.__CatalogObj, _ndeep) return self.GetCatalogObj()