I'm writing a python script that uses this awkward glob syntax.
import glob
F = glob.glob('./www.dmoz.org/Science/Environment/index.html')
F += glob.glob('./www.dmoz.org/Science/Environment/*/index.html')
F += glob.glob('./www.dmoz.org/Science/Environment/*/*/index.html')
F += glob.glob('./www.dmoz.org/Science/Environment/*/*/*/index.html')
F += glob.glob('./www.dmoz.org/Science/Environment/*/*/*/*/index.html')
Seems like there ought to be a way to wrap this is one line:
F = glob.glob('./www.dmoz.org/Science/Environment/[super_wildcard]/index.html')
But I don't know what the appropriate super wildcard would be. Does such a thing exist?
Sorry - it does not. You will have to probably write few lines of code using os.walk:
for root, dirs, files in os.walk('/starting/path/'):
for myFile in files:
if myFile == "index.html":
print os.path.join(root, myFile)
I have just released Formic which implements exactly the wildcard you need - '**' - in an implementation of Apache Ant's FileSet and Globs.
The search can be implemented:
import formic
fileset = formic.FileSet(include="/www.dmoz.org/Science/Environment/**/index.html")
for file_name in fileset.qualified_files():
# Do something with file_name
This will search from the current directory. I hope this helps.
I don't know if this is new, but glob CAN do this now.
For example,
F = glob.glob('./www.dmoz.org/Science/Environment/**/index.html', recursive=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With