This morning I was writing a script that operates on every html file on my hard disk. I was just going to have my script read the output of ”find . -name ’*.html’”, but then I remembered Python 2.3’s os.walk() function. Here’s the code to find my html files:
import osdef htmlFiles():
for (path, dames, fnames) in os.walk(“C:\\”):
for fn in fnames:
if fn.endswith(”.html”):
yield os.path.join(path, fn)
Very neat.
Update: Added the import and the os.path.join().