Le Tue, 9 Jun 2009 17:40:26 +0200,
Sander Sweers <[email protected]> s'exprima ainsi:

> 2009/6/9 spir <[email protected]>:
> > is there a way to make glob work in a specified dir?
> 
> glob needs a pathname and uses the current dir if no full path is
> given. Prepend the path to your match (*.txt in example below) and it
> works like you want it.
> 
> >>> import glob
> >>> glob.glob('c:\\GTK\\*.txt')
> ['c:\\GTK\\license.txt']
> 
> Greets
> Sander

Thank you. That was so simple I couldn't figure it out myself ;-)

What I was expecting is:

import os, glob
def dirglob(dir, pattern):
   fullPattern = os.path.join(dir,pattern)
   return glob.glob(fullPattern)

(used e.g.
   print dirglob("/home/spir/prog/*/doc", "*.txt")
to get .txt files from only doc subdirs of all projects)

Denis
------
la vita e estrany
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to