parsing directory for certain filetypes

Tim Chase python.list at tim.thechases.com
Tue Mar 11 09:45:26 EDT 2008


royG wrote:
> On Mar 10, 8:03 pm, Tim Chase  wrote:
> 
>> In Python2.5 (or 2.4 if you implement the any() function, ripped
>> from the docs[1]), this could be rewritten to be a little more
>> flexible...something like this (untested):
>>
> 
> that was quite a good lesson for a beginner like me..
> thanks guys
> 
> 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..

Though it doesn't use glob, the 2nd solution I gave (the one that 
uses the any() function you quoted) should be able to handle an 
arbitrary number of extensions...

-tkc











More information about the Python-list mailing list