ich habe ein Problem an dem ich schon eine Weile zu knabbern habe.
Ich habe eine Methode geschrieben die mir ein Verzeichnis nach bestimmten Kriterien hin, nach bestimmten Dateien oder Ordnern durchsucht. Nun möchte ich die Zeit berechnen, die dafür benötigt wird.
Leider ist jedes Verzeichnis anders und ich benötige nun einige Faktoren um die Zeit so genau wie möglich bestimmen zu können.
Ich habe mir gedacht, das man auf die Eingenschaften eines Ordners zugreifen kann. Ich übergebe meiner Methode also einen Pfad: "C:\Test\MeineDaten" . In den Eigenschaften steht dieser Ordner enthält 8 Unterordner und 25 Datein. Anhand dieser Werte kann ich die Zeit ungefähr berechnen wenn ich die Zeit für das Durchsuchen von einem Ordner kenne. Dazu könnte man die Ordnergröße mit in die Rechnung einfließen lassen(Wie das geht weist ich schon).
Das Ganze möchte ich dann in einen Progress-Dialog einbauen. Hat jemand das schon mal gemacht oder hat vielleicht eine Idee?
Meine Methode sieht so aus (Bitte über den Inhalt der methode hinwegsehen, ist noch quick and dirty):
Code: Alles auswählen
def dirWalk(self, dir, option = 0):
"""walk a directory tree, using a generator
"""
errorPool = ["System Volume Information", "Documents and Settings", \
"Dokumente und Einstellungen", "ProgramData", "Programme", \
"Program Files", "Users", "Windows" ]
if option == 0:
searchKey = "\\DatDbs"
elif option == 1:
searchKey = ".SIK"
elif option == 2:
searchKey = "\\Setup"
elif option == 3:
searchKey = ".bak"
for element in os.listdir(dir):
fullpath = os.path.join(dir, element)
if fullpath != dir + errorPool[0]\
and fullpath != dir + errorPool[1]\
and fullpath != dir + errorPool[2]\
and fullpath != dir + errorPool[3]\
and fullpath != dir + errorPool[4]\
and fullpath != dir + errorPool[5]\
and fullpath != dir + errorPool[6]\
and fullpath != dir + errorPool[7]:
if os.path.isdir(fullpath) and not os.path.islink(fullpath):
if not len(os.listdir(fullpath)) and searchKey in fullpath:
yield fullpath + os.sep
else:
for x in self.dirWalk(fullpath, option): # recurse into subdir
yield x
elif(searchKey in fullpath):
if option == 0:
yield os.path.split(fullpath)[0]
elif option == 1:
yield os.path.split(fullpath)[0]
elif option == 2:
yield os.path.split(fullpath)[0]
elif option == 3:
yield fullpath
schaf220