Jun-13-2017, 05:07 PM
As mention is pretty easy to write this with os.walk().
scandir has been taken into standard library.
os.walk()
has also gotten a lot faster in Python 3.5-->.scandir has been taken into standard library.
Quote:In practice, removing all those extra system calls makes os.walk() about 7-50 times as fast on Windows,
and about 3-10 times as fast on Linux and Mac OS X.
So we're not talking about micro-optimizations.
import os source = '/foo' for root,dirs,files in os.walk(source): for f_name in files: if f_name.endswith(('.pyc', '.txt')): f_name = os.path.join(root, f_name) print(f_name) # Test to see that's it okay first #os.remove(f_name)