parsing directory for certain filetypes

jay graves jaywgraves at gmail.com
Tue Mar 11 09:34:03 EDT 2008


On Mar 11, 12:21 am, royG <roygeor... at gmail.com> wrote:
> On Mar 10, 8:03 pm, Tim Chase  wrote:
> in the version using glob()
>
> >path = os.path.normpath(os.path.join(folder, '*.txt'))
> >lst = glob.glob(path)
>
> is it possible to check for more than one file extension? here i will
> have to create two path variables like
> path1 = os.path.normpath(os.path.join(folder, '*.txt'))
> path2 = os.path.normpath(os.path.join(folder, '*.doc'))
>
> and then use glob separately..
> or is there another way?

use a loop. (untested)

def parsefolder(folder):
    lst = []
    for pattern in ('*.txt','*.doc'):
        path = os.path.normpath(os.path.join(folder, pattern))
        lst.extend(glob.glob(path))
    lst.sort()
    return lst




More information about the Python-list mailing list