Cria uma lista com todos os arquivos de um determinado diretório recursivamente.
Código
1 # -*- coding: utf-8 -*-
2
3 import os
4 import string
5
6
7 class DirFileList:
8 def __init__(self):
9 self._dirFileList = []
10
11 def __listDirs(self, path):
12 try:
13 if os.path.isfile(path) is True:
14 self._dirFileList.append(path)
15 else:
16 abspath = map(lambda x: os.path.join(path, x),
17 os.listdir(path))
18 if abspath is not []:
19 map(lambda x: self.__listDirs(x), abspath)
20 except:
21 self._dirFileList.extend(path)
22
23 def getDirFileList(self):
24 return self._dirFileList
25
26 def setDirFileList(self, path):
27 self.__listDirs(path)
28
29 dirFileList = property(fget=getDirFileList, fset=setDirFileList)
Volta para CookBook.