mit Python Verzeichnisse rekursiv durchsuchen?
Harald Massa
cpl.19.ghum at spamgourmet.com
Wed Mar 26 13:06:23 EST 2003
Jan,
> Ich habe ein Problem - ich will mit einem Python-Skript Verzeichnisse
> rekursiv nach einem bestimmtbaren Dateityp durchsuchen und die
> Ergebnisse nach Verzeichnissen sortiert in eine HTML oder LaTeX Datei
> ausgeben.
If you have problems with the os.path.walk or sth. like that (I did not
understand that either), just go to
http://www.jorendorff.com/articles/python/path/
Example (from that page) to delete emacs backup-files:
# with os.path.walk
def delete_backups(arg, dirname, names):
for name in names:
if name.endswith('~'):
os.remove(os.path.join(dirname, name))
os.path.walk(os.environ['HOME'], delete_backups, None)
# with path
dir = path(os.environ['HOME'])
for f in dir.walkfiles('*~'):
f.remove()
So I would recommend installing "path". It's a great module, and free
(German:
falls Dir os.path.walk zu knifflig ist: gehe auf die angegebene URL und
lade das "PATH" Modul herunter. Macht Directory Tree Traversal deutlich
einfacher)
Gruß
Harald
More information about the Python-list
mailing list