[Tutor] skip some directories

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue May 31 03:31:13 CEST 2005



On Mon, 30 May 2005, Jonas Melian wrote:

> I'm trying to working with some directories only
>
> import os
> dirName = "/usr/share/fonts/"
> dirBase = ['misc','TTF','Type1','CID','100dpi','75dpi'] # directories to
> skip
>
> for root, dirs, files in os.walk(dirName):
>     for end in dirBase:
>         if root.endswith(end):
>             print 'skiped'
>         else:
>             print root

Hi Jonas,


Let's break out the logic a little bit.  Would it be accurate to write
this as:

### Pseudocode ###
for root, dirs, files in os.walk(dirName):
    if weShouldSkipThis(root):
        print "skipped"
    else:
        print root
######

and would this be more accurate to what you're trying to do?  If so, then
all you need to do is concentrate on weShouldSkipThis().  Making a
separate helper function there should help you get it working properly.

If you have more questions, please feel free to ask.



More information about the Tutor mailing list