Use os.walk() instead of listdir+recurse in two sensible places.