473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

determine directories with wildcard

Hello,

I want to collect with the wildcard '*' all existing directories.
For example: /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*

How can I resolve this problem?

Thanks for your hints, Thomas.
Jul 18 '05 #1
5 1806
Thomas Rademacher wrote:
Hello,

I want to collect with the wildcard '*' all existing directories.
For example: /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*

How can I resolve this problem?


This is some sort of pattern matching. What I'd do is to convert your
pattern to a regex:

rex = re.compile(r"/dir/dir/.*/dir/.*/dir/.*")

Then create a list of dirs with os.walk:

dirs = [dirpath for dirpath, foo, bar in os.walk(topdir) if
rex.match(dirpath)]
This is untested, but should do the trick.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
On Tuesday 08 March 2005 14:33, Thomas Rademacher wrote:
How can I resolve this problem?


python
import glob
help(glob)


or look at the online documentation for glob.

--
--- Heiko.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQBCLau7f0bpgh6uVAMRAq7EAJ9XgYPfTiwfSCR4AOgKko AXeb0jRQCbBw/e
uLCTnWwkK5wansgRM1JsGKU=
=Gplj
-----END PGP SIGNATURE-----

Jul 18 '05 #3
Thomas Rademacher wrote:
Hello,

I want to collect with the wildcard '*' all existing directories.
For example: /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*

How can I resolve this problem?

Thanks for your hints, Thomas.


You may want to check out the glob module. E.g. something like:
import glob, os
p = "c:/*/*/site-packages/*"
dirs = [d for d in glob.glob(p) if os.path.isdir(d)]
print dirs

['c:/Python23\\Lib\\site-packages\\atox',
'c:/Python23\\Lib\\site-packages\\BDBStorage',
'c:/Python23\\Lib\\site-packages\\BitTorrent',
'c:/Python23\\Lib\\site-packages\\BTrees',
'c:/Python23\\Lib\\site-packages\\ChartDirector',
'c:/Python23\\Lib\\site-packages\\cjkcodecs',
'c:/Python23\\Lib\\site-packages\\ctypes',
'c:/Python23\\Lib\\site-packages\\CVS',
'c:/Python23\\Lib\\site-packages\\elementtree',
'c:/Python23\\Lib\\site-packages\\enchant',
'c:/Python23\\Lib\\site-packages\\Ft',
'c:/Python23\\Lib\\site-packages\\imdb',
'c:/Python23\\Lib\\site-packages\\isapi',
'c:/Python23\\Lib\\site-packages\\logilab',
'c:/Python23\\Lib\\site-packages\\mx',
'c:/Python23\\Lib\\site-packages\\MySQLdb',
'c:/Python23\\Lib\\site-packages\\numarray',
'c:/Python23\\Lib\\site-packages\\OpenGL',
'c:/Python23\\Lib\\site-packages\\OpenGLContext',
'c:/Python23\\Lib\\site-packages\\parallel',
'c:/Python23\\Lib\\site-packages\\Persistence',
'c:/Python23\\Lib\\site-packages\\PIL',
'c:/Python23\\Lib\\site-packages\\psyco',
'c:/Python23\\Lib\\site-packages\\py2exe',
'c:/Python23\\Lib\\site-packages\\pychecker',
'c:/Python23\\Lib\\site-packages\\pynsource',
'c:/Python23\\Lib\\site-packages\\Pyrex',
'c:/Python23\\Lib\\site-packages\\Pyro',
'c:/Python23\\Lib\\site-packages\\pythonwin',
'c:/Python23\\Lib\\site-packages\\pywin32_system32',
'c:/Python23\\Lib\\site-packages\\pyXLWriter',
'c:/Python23\\Lib\\site-packages\\reportlab',
'c:/Python23\\Lib\\site-packages\\serial',
'c:/Python23\\Lib\\site-packages\\spambayes',
'c:/Python23\\Lib\\site-packages\\ThreadedAsync',
'c:/Python23\\Lib\\site-packages\\vrml',
'c:/Python23\\Lib\\site-packages\\win32',
'c:/Python23\\Lib\\site-packages\\win32com',
'c:/Python23\\Lib\\site-packages\\win32comext',
'c:/Python23\\Lib\\site-packages\\wx',
'c:/Python23\\Lib\\site-packages\\wxPython',
'c:/Python23\\Lib\\site-packages\\ZConfig',
'c:/Python23\\Lib\\site-packages\\zdaemon',
'c:/Python23\\Lib\\site-packages\\ZEO',
'c:/Python23\\Lib\\site-packages\\zLOG',
'c:/Python23\\Lib\\site-packages\\ZODB',
'c:/Python23\\Lib\\site-packages\\ZopeUndo',
'c:/Python23\\Lib\\site-packages\\_xmlplus',
'c:/Python24\\Lib\\site-packages\\ChartDirector',
'c:/Python24\\Lib\\site-packages\\elementtidy',
'c:/Python24\\Lib\\site-packages\\elementtree',
'c:/Python24\\Lib\\site-packages\\isapi',
'c:/Python24\\Lib\\site-packages\\py2exe',
'c:/Python24\\Lib\\site-packages\\pythonwin',
'c:/Python24\\Lib\\site-packages\\pywin32_system32',
'c:/Python24\\Lib\\site-packages\\win32',
'c:/Python24\\Lib\\site-packages\\win32com',
'c:/Python24\\Lib\\site-packages\\win32comext',
'c:/Python24\\Lib\\site-packages\\wx-2.5.3-msw-unicode']
--

Vincent Wehren
Jul 18 '05 #4
On Tue, 8 Mar 2005 14:33:59 +0100, Thomas Rademacher
<ra********@prostep.fta-berlin.de> wrote:
Hello,

I want to collect with the wildcard '*' all existing directories.
For example: /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*


How about something like:

import fnmatch
import os

root = 'd:\\'
filter = r'*\*python*\*'

for dirpath, dirnames, filenames in os.walk(root):
if fnmatch.fnmatch(dirpath, filter):
print 'matched', dirpath

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Jul 18 '05 #5
Thanks. It works fine! Thomas
"Vincent Wehren" <vi*****@visualtrans.de> schrieb im Newsbeitrag
news:d0**********@news1.zwoll1.ov.home.nl...
Thomas Rademacher wrote:
Hello,

I want to collect with the wildcard '*' all existing directories.
For example: /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*

How can I resolve this problem?

Thanks for your hints, Thomas.


You may want to check out the glob module. E.g. something like:
>> import glob, os
>> p = "c:/*/*/site-packages/*"
>> dirs = [d for d in glob.glob(p) if os.path.isdir(d)]
>> print dirs

['c:/Python23\\Lib\\site-packages\\atox',
'c:/Python23\\Lib\\site-packages\\BDBStorage',
'c:/Python23\\Lib\\site-packages\\BitTorrent',
'c:/Python23\\Lib\\site-packages\\BTrees',
'c:/Python23\\Lib\\site-packages\\ChartDirector',
'c:/Python23\\Lib\\site-packages\\cjkcodecs',
'c:/Python23\\Lib\\site-packages\\ctypes',
'c:/Python23\\Lib\\site-packages\\CVS',
'c:/Python23\\Lib\\site-packages\\elementtree',
'c:/Python23\\Lib\\site-packages\\enchant',
'c:/Python23\\Lib\\site-packages\\Ft',
'c:/Python23\\Lib\\site-packages\\imdb',
'c:/Python23\\Lib\\site-packages\\isapi',
'c:/Python23\\Lib\\site-packages\\logilab',
'c:/Python23\\Lib\\site-packages\\mx',
'c:/Python23\\Lib\\site-packages\\MySQLdb',
'c:/Python23\\Lib\\site-packages\\numarray',
'c:/Python23\\Lib\\site-packages\\OpenGL',
'c:/Python23\\Lib\\site-packages\\OpenGLContext',
'c:/Python23\\Lib\\site-packages\\parallel',
'c:/Python23\\Lib\\site-packages\\Persistence',
'c:/Python23\\Lib\\site-packages\\PIL',
'c:/Python23\\Lib\\site-packages\\psyco',
'c:/Python23\\Lib\\site-packages\\py2exe',
'c:/Python23\\Lib\\site-packages\\pychecker',
'c:/Python23\\Lib\\site-packages\\pynsource',
'c:/Python23\\Lib\\site-packages\\Pyrex',
'c:/Python23\\Lib\\site-packages\\Pyro',
'c:/Python23\\Lib\\site-packages\\pythonwin',
'c:/Python23\\Lib\\site-packages\\pywin32_system32',
'c:/Python23\\Lib\\site-packages\\pyXLWriter',
'c:/Python23\\Lib\\site-packages\\reportlab',
'c:/Python23\\Lib\\site-packages\\serial',
'c:/Python23\\Lib\\site-packages\\spambayes',
'c:/Python23\\Lib\\site-packages\\ThreadedAsync',
'c:/Python23\\Lib\\site-packages\\vrml',
'c:/Python23\\Lib\\site-packages\\win32',
'c:/Python23\\Lib\\site-packages\\win32com',
'c:/Python23\\Lib\\site-packages\\win32comext',
'c:/Python23\\Lib\\site-packages\\wx',
'c:/Python23\\Lib\\site-packages\\wxPython',
'c:/Python23\\Lib\\site-packages\\ZConfig',
'c:/Python23\\Lib\\site-packages\\zdaemon',
'c:/Python23\\Lib\\site-packages\\ZEO',
'c:/Python23\\Lib\\site-packages\\zLOG',
'c:/Python23\\Lib\\site-packages\\ZODB',
'c:/Python23\\Lib\\site-packages\\ZopeUndo',
'c:/Python23\\Lib\\site-packages\\_xmlplus',
'c:/Python24\\Lib\\site-packages\\ChartDirector',
'c:/Python24\\Lib\\site-packages\\elementtidy',
'c:/Python24\\Lib\\site-packages\\elementtree',
'c:/Python24\\Lib\\site-packages\\isapi',
'c:/Python24\\Lib\\site-packages\\py2exe',
'c:/Python24\\Lib\\site-packages\\pythonwin',
'c:/Python24\\Lib\\site-packages\\pywin32_system32',
'c:/Python24\\Lib\\site-packages\\win32',
'c:/Python24\\Lib\\site-packages\\win32com',
'c:/Python24\\Lib\\site-packages\\win32comext',
'c:/Python24\\Lib\\site-packages\\wx-2.5.3-msw-unicode']
--

Vincent Wehren

Jul 18 '05 #6

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

Similar topics

1
by: Generic Usenet Account | last post by:
Here's the requirement that I am trying to satisfy: Handle wildcards in STL such that the wildcard entry is encountered before non-wildcard entries while traversing containers like sets and...
1
by: deko | last post by:
I have a form where users can enter a string with asterisks to perform a wildcard search. Currently, the string entered by the user looks like this: *somestring* The purpose is to match any...
4
by: Grant Harmeyer | last post by:
How would I set up an httpHandler so that it would only apply to certain child directories of the application? I.E: <httpHandlers> <add verb="*" path="/files/*/*/*/*.aspx"...
3
by: Adam | last post by:
Its my understanding that in asp.net 2.0 you can write an httpmodule that will acts as a wildcard handler and pass requests on to the proper engine, for instance, asp or perl for example, In the...
3
by: Dan W | last post by:
Hi there. I am parsing a text file and as I parse each line I need to go out to two different directories and check to see if any files beginning with the string I just parsed exist. For...
6
by: Jan Kucera | last post by:
Hi, does anybody know about wildcard mapping ASP.NET 2 in IIS6? Any tutorial? Thanks, Jan
1
by: SoxFan44 | last post by:
Hi, What's the best way to watch several directories (not sub dirs) with FileSystemWatcher? Should I create an array of them, vector, or something else? Also, performance-wise, how many...
12
by: Pablo Suarez | last post by:
When I code #include "myheader.h" then this header file is searched in the current directory. But where does the compiler search the header file when I write #include <myheader.h>
25
by: smarty | last post by:
how to create folders/directories in C. are there any library functions for these?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.