path stuff

kyosohma at gmail.com kyosohma at gmail.com
Wed May 9 14:19:11 EDT 2007


On May 9, 1:11 pm, fscked <fsckedag... at gmail.com> wrote:
> 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?
>
> eg
>
> d:\dir\mydir1\filename.txt                      <----------I want to
> see this one
> d:\dir\mydir2\archived\filename.txt         <----------I don't want to
> see anything in the "archived" directory
> d:\dir\mydir2\filename.txt                      <----------Again, I do
> want to see this one
>
> I am having a bit of trouble figuring out how to use the path module
> to hack up the path to determine if I am in a subdir I care about. So
> either don show me the results from a certain directory or just plain
> skip a certain directory.

Hi,

One way to do it would be to grab just the directory path like this:

dirPath = os.path.dirname(path)

and then use and if:

if 'archived' in dirPath:
   # skip this directory

That should get you closer to the answer anyway.

Mike




More information about the Python-list mailing list