Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > trouble with os.path.exists() and wildcards

Reply
Thread Tools

trouble with os.path.exists() and wildcards

 
 
Fernando Rodriguez
Guest
Posts: n/a
 
      11-17-2003
Hi,

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...
 
Reply With Quote
 
 
 
 
Erik Max Francis
Guest
Posts: n/a
 
      11-17-2003
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.

--
Erik Max Francis && && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \
\__/ Get married, but never to a man who is home all day.
-- George Bernard Shaw
 
Reply With Quote
 
 
 
 
Eric Williams
Guest
Posts: n/a
 
      11-17-2003
Fernando Rodriguez wrote:

> Hi,
>
> 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...


have you taken a look at glob.glob?

import glob, os

dirname="."
filespec="ppis-*.iss"

print glob.glob(os.path.join(dirname, filespec))

cya,
Eric

--
---
s- should be removed to contact me...
 
Reply With Quote
 
Jeremy Fincher
Guest
Posts: n/a
 
      11-17-2003
Erik Max Francis <> wrote in message news:<>...
> 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?

Jeremy
 
Reply With Quote
 
Erik Max Francis
Guest
Posts: n/a
 
      11-17-2003
Jeremy Fincher wrote:

> Erik Max Francis <> wrote in message
> news:<>...
>
> > 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?

--
Erik Max Francis && && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \
\__/ Why don't you grow up for crying out loud?
-- Capt. Benjamin "Hawkeye" Pierce
 
Reply With Quote
 
Bengt Richter
Guest
Posts: n/a
 
      11-17-2003
On Mon, 17 Nov 2003 11:09:58 -0800, Erik Max Francis <> wrote:

>Jeremy Fincher wrote:
>
>> Erik Max Francis <> wrote in message
>> news:<>...
>>
>> > 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
 
Reply With Quote
 
Fernando Rodriguez
Guest
Posts: n/a
 
      11-18-2003
On 17 Nov 2003 22:17:25 GMT, (Bengt Richter) wrote:


>>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.,


Yes, that exactly what I wanted, and the glob trick works fine. Thanks.


 
Reply With Quote
 
Jeremy Fincher
Guest
Posts: n/a
 
      11-18-2003
Erik Max Francis <> wrote in message news:<>...
> Jeremy Fincher wrote:
>
> > Erik Max Francis <> wrote in message
> > news:<>...
> >
> > > 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.


Ah, you misunderstand; my problem was with the "and then
os.path.exists in a loop" part, since, by definition, the files
returned by glob.glob will exist I was just trying to kindly point
out that os.path.exists isn't needed for his purposes. I guess I
could've been more clear

Jeremy
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java 5, Generic, Map and wildcards Benjamin Lerman Java 1 03-09-2006 01:03 PM
Bounded wildcards and type compatibility John C. Bollinger Java 6 01-04-2006 05:06 PM
File names for monitoring must have absolute paths, and no wildcards. msnews.microsoft.com ASP .Net 0 07-18-2004 08:41 PM
Negative Lookbehind and Wildcards Thomas F. O'Connell Perl 1 02-28-2004 01:50 PM
newbie: wildcards AND local element declarations Mike Kayser XML 0 08-22-2003 06:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57