Glob in python which supports the ** wildcard

Kurt Mueller kurt.alfred.mueller at sunrise.ch
Mon Nov 22 23:54:14 CET 2010


Hi,


Am 22.11.2010 um 23:05 schrieb Stefan Sonnenberg-Carstens:
> Am 22.11.2010 22:43, schrieb Martin Lundberg:
>> I want to be able to let the user enter paths like this:
>> apps/name/**/*.js
>> and then find all the matching files in apps/name and all its
>> subdirectories. However I found out that Python's glob function
>> doesn't support the recursive ** wildcard. Is there any 3rd party glob
>> function which do support **?
> os.walk() or os.path.walk() can be used.
> You need to traverse the file system.
> AFAIK there is no support for this.


If you are a lucky Unix/Linux/MacOS user:
---------------------------------------------------------------------------
#!/usr/bin/env python
# find files
import os
cmd = 'find apps/name/ -type f -name "*.js" -print'     # find is a standard Unix tool
for filename in os.popen(cmd).readlines():              # run find command
    # do something with filename 
---------------------------------------------------------------------------

find is very powerful, really.


Have anice day
-- 
kurt.alfred.mueller at gmail.com




More information about the Python-list mailing list