473,589 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 30167
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.pa th.join(dirname , filespec))

cya,
Eric

--
---
s- should be removed to contact me...
Jul 18 '05 #3
Erik Max Francis <ma*@alcyone.co m> wrote in message news:<3F******* ********@alcyon e.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.co m> wrote in message
news:<3F******* ********@alcyon e.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.co m> wrote:
Jeremy Fincher wrote:
Erik Max Francis <ma*@alcyone.co m> wrote in message
news:<3F******* ********@alcyon e.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(patte rn): print 'there is at least one file matching %r'%pattern
else: print 'no files match the %r pattern'%patter n

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.co m> wrote in message news:<3F******* *******@alcyone .com>...
Jeremy Fincher wrote:
Erik Max Francis <ma*@alcyone.co m> wrote in message
news:<3F******* ********@alcyon e.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
1351
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 want an img element to generate an ugly blank box. I know the physical location of the image(s) in question, and figured I'd use os.path.exists to see if each file exists. A quick test in the interpreter yields: >>> os.path.exists(u'S:/Scans/Projects/2004/TJ/04TJ0267.jpg') True
4
2988
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 (#60, Nov 30 2004, 11:49:19) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.path.exists('Lib/os.py') True # expected
11
4641
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 'SSW-10%'; returns what I expect: PN Qty SSW-101-01-T-D 1780 SSW-101-01-T-D 1780 SSW-102-01-G-D 8900
9
1650
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 a text box. It works fine on my computer, but I get the following stack trace: System.IO.DirectoryNotFoundException: Could not find a part of the path "D:\". at System.IO.__Error.WinIOError
0
2185
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 read the values. Below is the code. Now, it reads CSV file without any issues only if all the fields are not null. If any field is blank, it moves the values to the left and displays the value under invalid column. Example is shown below: A part of CSV file. I am reading the first row as...
1
2165
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. In Java, I can preprocess, via a filter, some HTTP requests before answering to the client. Please allow me to show and example since it will illustrate the point well. User types: http://domain.com/myapp/restofpath.html
0
2282
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 setup: module: tester.py: ----------------- import imp def loader(mname, mpath): fp, pathname, description = imp.find_module(mname,)
1
1776
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 local machine, this is the code i have: string inputString = Convert.ToString(reader); byte AttachmentByte; AttachmentByte = StringToByteArray(inputString); string dir = "";
5
13338
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 is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
7931
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7865
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8233
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8224
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5731
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3849
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.