On 09/12/2008, Damon Timm <[EMAIL PROTECTED]> wrote:
> Basically: how do I make it match *.flac ? I couldn't find anything
> on google (searching for "python index" just gets me a lot of indexes
> of python docs - wink)
Hi Damon,
The fnmatch module will help here. It basically implements unix-style
filename patterns. For example:
import os
import fnmatch
files = os.listdir('.')
flac_files = fnmatch(files, '*.flac')
So, to test whether you have any flac files, you can just test whether
fnmatch(files, '*.flac') is empty.
If you wanted to roll your own solution (the fnmatch module is a bit
obscure, I think), you could do something with os.path.splitext:
files = os.listdir('.')
extensions = [os.path.splitext(f)[1] for f in files]
if '.flac' in extensions:
print 'FLAC files found!'
HTH!
--
John.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor