首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

DiskWalk 遍历目录树工具种

2012-10-07 
DiskWalk 遍历目录树工具类import osclass DiskWalk(object):API for getting directory walking colle

DiskWalk 遍历目录树工具类

import osclass DiskWalk(object):    '''    API for getting directory walking collections    '''    def __init__(self, path):        if path is None or len(path) == 0:            print 'Error: Please enter a valid path!'            return False        self.path = path    def enumeratePaths(self):        '''        Returns the path to all the files in a directory as a list        '''        path_collection = []        for dirpath, dirnames, filenames in os.walk(self.path):            for file in filenames:                fullpath = os.path.join(dirpath, file)                path_collection.append(fullpath)        return path_collection    def enumerateFiles(self):        '''        Returns all the files in a directory as a list        '''        path_collection = []        for dirpath, dirnames, filenames in os.walk(self.path):            for file in filenames:                path_collection.append(file)        return path_collection    def enumerateDir(self):        '''        Returns all the directories in a directory as a list        '''        path_collection = []        for dirpath, dirnames, filenames in os.walk(self.path):            for dir in dirnames:                path_collection.append(dir)        return path_collection
?

热点排行