Ich habe eine Klasse zum durchsuchen von Directories und Filtern bestimmter Dateien aus diesen.
Sieht ungefähr so aus:
Code: Alles auswählen
import os, string, sys
class DirParser:
def __init__(self, sourcedir):
self.sourcedir=sourcedir
self.filename=""
self.fileList=[]
def getFiles(self, filename):
self.searchInDirectory(self.sourcedir)
return self.fileList
#search all index.xml-files in our directory
def searchInDirectory(self, sPath):
#create a list with current directory
try:
lDirContent=os.listdir(sPath)
# in case of an error (e.g. permission denied), leave function
except WindowsError, e:
print e
return
lDirContent=lDirList+lFileList
#go through the entries in our directory-list
for x in lDirContent:
sLookIn=os.path.join(sPath,x)
#if this is a directory, call function recursive to traverse
if os.path.isdir(sLookIn):
self.searchInDirectory(sLookIn)
# if this is an index-file
elif sLookIn==sPath+"\\index.xml":
print "Parsing File: "+sLookIn
self.fileList.append(sLookIn)
Code: Alles auswählen
import DirParser
myDirs=DirParser("c:\\files")
filelist=myDirs.getFiles("index.xml")
print filelist
Code: Alles auswählen
Traceback (most recent call last):
File "C:\PROGRA~1\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\myPython\teststart.py", line 3, in ?
myDirs=DirParser("c:\\files")
TypeError: 'module' object is not callable
Weiss jemand Rat?