On May 10, 1:43 pm, fscked <[EMAIL PROTECTED]> wrote: > On May 10, 12:45 pm, fscked <[EMAIL PROTECTED]> wrote: > > > > > > > On May 10, 10:41 am, fscked <[EMAIL PROTECTED]> wrote: > > > > On May 9, 7:02 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > > > > > En Wed, 09 May 2007 15:11:06 -0300, fscked <[EMAIL PROTECTED]> > > > > escribió: > > > > > > I am walking some directories looking for a certain filename pattern. > > > > > This part works fine, but what if I want to exclude results from a > > > > > certain directory being printed? > > > > > Using os.walk you can skip undesired directories entirely: > > > > > for dirpath, dirnames, filenames in os.walk(starting_dir): > > > > if "archived" in dirnames: > > > > dirnames.remove("archived") > > > > # process filenames, typically: > > > > for filename in filenames: > > > > fullfn = os.path.join(dirpath, filename) > > > > ... > > > > > -- > > > > Gabriel Genellina > > > > OK, this is on Winbloze and it keeps giving me "The directory name is > > > invalid: u"blahblahblah" with double backslashies everywhere. I am > > > currently trying to figure out how to make those go away. I shall > > > check back in a bit. > > > > thanks for all the help so far. :)- Hide quoted text - > > > > - Show quoted text - > > > ok, got the backslashies fixed, not I want it to print just a single > > line for each matching filename and dirpath, but it prints 3... hmm...- > > Hide quoted text - > > > - Show quoted text - > > Nevermind, I am indentationally challenged. I was printing under the > for dirpath, dirname, filename part and had to unindent uno time. > > It works as desired now, thanks!- Hide quoted text - > > - Show quoted text -
ok, I lied, it is still doing the archived folders. Here is the code: import os, sys from path import path myfile = open("boxids.txt", "r", 0) for line in myfile: d = 'D:\\Dir\\' + path(line.strip()) for f in d.walkfiles('*Config*.xml'): for dirpath, dirnames, filenames in os.walk(d): if "Archived" in dirnames: dirnames.remove("Archived") #skip this directory print f print 'Done' when it does the print f it still shows me the dirs i don't want to see. any more ideas? TIA -- http://mail.python.org/mailman/listinfo/python-list