472,348 Members | 1,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

trouble with os.path.exists() and wildcards

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...
Jul 18 '05 #1
7 28275
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 && ma*@alcyone.com && 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
Jul 18 '05 #2
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...
Jul 18 '05 #3
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?

Jeremy
Jul 18 '05 #4
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?

--
Erik Max Francis && ma*@alcyone.com && 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
Jul 18 '05 #5
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
Jul 18 '05 #6
On 17 Nov 2003 22:17:25 GMT, bo**@oz.net (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. :-)
Jul 18 '05 #7
Erik Max Francis <ma*@alcyone.com> wrote in message news:<3F**************@alcyone.com>...
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.


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
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert Brewer | last post by:
I've got a webapp which is behaving oddly. I want to include an image on the webpage, but only if the physical file exists; if it doesn't, I don't...
4
by: Pierre Quentel | last post by:
os.path.exists(path) returns True if "path" exists But on Windows it also returns True for "path" followed by any number of dots : Python 2.4...
11
by: Randy Weber | last post by:
I am getting unexpected results with a Like Query using ASP and an Access database. This query - SELECT PN, Qty From Inventory Where PN Like...
9
by: Sheldon Cohen | last post by:
Hello, I am using c# and running a site that is on a shared host. The code in question is supposed to create a new directory that is coming out of...
0
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to...
1
by: TATrader | last post by:
Dearest Colleagues, I was suddenly having a sharp pain in locating information about a design capability in PHP that exists in Java servlets. ...
0
by: David Hirschfield | last post by:
I'm not entirely sure what's going on here, but I suspect it's related to my general lack of knowledge of the python import internals. Here's the...
1
Krantor
by: Krantor | last post by:
Hi all, i am quite new to c# and was wondering if i could get assistance on an issue im having with writing a binary file from the database to my...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.