Even though the glob API is small, the module packs a lot of power. It is useful in any situation where a program needs to look for a list of files on the file system with names matching a pattern. To create a list of filenames that all have a certain extension, prefix, or any common string in the middle, use glob instead of writing custom code to scan the directory contents.
In [1]:
import glob
for name in sorted(glob.glob('./*')):
print(name)
In [10]:
import glob
print('Name explicitly:')
for name in sorted(glob.glob('/Users/*')):
print(name)
print('Named with wildcard:')
for name in sorted(glob.glob('/Users/*/*')):
print(' {}'.format(name))