Exclude Directories from os.walk

Scott David Daniels Scott.Daniels at Acm.Org
Tue Oct 21 12:27:41 EDT 2008


D wrote:
> Hello,
> 
> How can one exclude a directory (and all its subdirectories) when
> running os.walk()?
> 
> Thanks,
> 
> Doug

for base, dirs, files in os.walk('wherever'):
     if 'RCS' in dirs:
         dirs.remove('RCS')

As described in the os.walk docs.


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list