On Mon, 17 Nov 2003 11:09:58 -0800, Erik Max Francis <ma*@alcyone.com> wrote:
Jeremy Fincher wrote:
Erik Max Francis <ma*@alcyone.com> wrote in message
news:<3F***************@alcyone.com>...
> Fernando Rodriguez wrote:
>
> > How can I check for the xistence of any file that matches a
> > wildcard?
> >
> > For example: ppis-*.iss
> >
> > os.path.exists() doesn't expand the wildcard...
>
> Use glob.glob and then os.path.exists in a loop.
Wouldn't the glob.glob only return files that actually exist?
Sure, but isn't that what he wants? He wrote, "the [existence] of any
file that maches a wildcard." He's obviously talking about existing
files.
Besides, what else could expanding a wildcard mean except enumerating
every possible match?
Sure, but then what? Maybe the OP was only interested if _any_ matches existed. E.g.,
pattern = 'ppis-*.iss'
if glob.glob(pattern): print 'there is at least one file matching %r'%pattern
else: print 'no files match the %r pattern'%pattern
might be reasonable to do in some context -- without looking at the actual matches, if any.
Maybe this is what Jeremy had in mind (a lot of mind reading around here ;-)
Regards,
Bengt Richter