-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileWalker.py
executable file
·36 lines (28 loc) · 1.24 KB
/
FileWalker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import re
class FileWalker():
""" holds the files for a given folder """
def __init__(self, name="Example Folder", pathToFolder="./"):
try:
os.stat(pathToFolder)
except OSError:
print "Folder doesn't exist"
raise
self.regexp = re.compile(r'.*\.(git|svn).*', re.IGNORECASE)
self.path = pathToFolder
self.name = name
self.files = [] # list of files
self.__fetchAllFiles()
def getFiles(self):
return self.files
def __fetchAllFiles(self):
for dirpath, dnames, fnames in os.walk(self.path):
for f in fnames:
pathToFile = os.path.join(dirpath, f)
if not self.regexp.match(pathToFile):
self.files.append(pathToFile)
def __str__(self):
returnStr = "Folder: %s\n" % (self.name)
returnStr += " Files: %d\n" % len(self.files)
returnStr += " Path : %s \n" % self.path
return returnStr