path stuff

fscked fsckedagain at gmail.com
Fri May 11 12:25:55 EDT 2007


On May 10, 6:08 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Thu, 10 May 2007 19:04:30 -0300, fscked <fsckedag... at gmail.com>  
> escribió:
>
>
>
>
>
> > 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.
>
> You are walking the directory structure *twice*, using two different  
> methods at the same time. Also, there is no standard `path` module, and  
> several implementations around, so it would be a good idea to tell us  
> which one you use.
> If you want to omit a directory, and include just filenames matching a  
> pattern:
>
> import os, sys, os.path, fnmatch
>
> def findinterestingfiles(root_dir):
>    for dirpath, dirnames, filenames in os.walk(root_dir):
>      if "Archived" in dirnames:
>        dirnames.remove("Archived")
>      for filename in fnmatch.filter(filenames, '*Config*.xml'):
>        fullfn = os.path.join(dirpath, filename)
>        print fullfn
>
> myfile = open("boxids.txt", "r")
> for line in myfile:
>    dirname = os.path.join('D:\\Dir\\', line.strip())
>    findinterestingfiles(dirname):
> myfile.close()
>
> --
> Gabriel Genellina- Hide quoted text -
>
> - Show quoted text -

Should this code work? I get a syntax error and cannot figure out why.




More information about the Python-list mailing list