determine directories with wildcard

Vincent Wehren vincent at visualtrans.de
Tue Mar 8 08:46:33 EST 2005


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



More information about the Python-list mailing list