collect all directories matching criteria from directory tree in python -


How can I collect all the criteria from a directory with frequency (like 'Keep file with name') tree? Some kind:

  def has_my_file (d): return ('foo.txt' in os.listdir (d)) walk_tree (dirname, criterion = has_my_file)  

For tree:

  home / bob / foo.txt sally / mike / foo.txt  

walk_tree Should return:

/ P>

Use:

  Import OS results = [] For parents, DS, FS in OS Walkle (DIARNA): If FS 'foo.txt' in FS: result.append (parent)  < / Pre> 

Use list comprehension:

  result = [parent, ds, fs o for parents Number of 'Fooktxt' If Waske (Diaiarana) FS]  

Comments