1 \section{Standard Module
\module{glob
}}
5 The
\module{glob
} module finds all the pathnames matching a specified
6 pattern according to the rules used by the
\UNIX{} shell. No tilde
7 expansion is done, but
\code{*
},
\code{?
}, and character ranges
8 expressed with
\code{[]} will be correctly matched. This is done by
9 using the
\function{os.listdir()
} and
\function{fnmatch.fnmatch()
}
10 functions in concert, and not by actually invoking a subshell. (For
11 tilde and shell variable expansion, use
\function{os.path.expanduser()
}
12 and
\function{os.path.expandvars()
}.)
14 \begin{funcdesc
}{glob
}{pathname
}
15 Returns a possibly-empty list of path names that match
\var{pathname
},
16 which must be a string containing a path specification.
17 \var{pathname
} can be either absolute (like
18 \file{/usr/src/Python-
1.5/Makefile
}) or relative (like
19 \file{../../Tools/*.gif
}), and can contain shell-style wildcards.
22 For example, consider a directory containing only the following files:
23 \file{1.gif
},
\file{2.txt
}, and
\file{card.gif
}.
\function{glob()
}
24 will produce the following results. Notice how any leading components
25 of the path are preserved.
29 >>> glob.glob('./
[0-
9].*')
30 ['./
1.gif', './
2.txt'
]
31 >>> glob.glob('*.gif')
33 >>> glob.glob('?.gif')