Updated for 2.1a3
[python/dscho.git] / Doc / lib / libglob.tex
blob5c1de807bb168661f7ba6b149e1d50da97164cf0
1 \section{\module{glob} ---
2 \UNIX{} style pathname pattern expansion}
4 \declaremodule{standard}{glob}
5 \modulesynopsis{\UNIX\ shell style pathname pattern expansion.}
8 The \module{glob} module finds all the pathnames matching a specified
9 pattern according to the rules used by the \UNIX{} shell. No tilde
10 expansion is done, but \code{*}, \code{?}, and character ranges
11 expressed with \code{[]} will be correctly matched. This is done by
12 using the \function{os.listdir()} and \function{fnmatch.fnmatch()}
13 functions in concert, and not by actually invoking a subshell. (For
14 tilde and shell variable expansion, use \function{os.path.expanduser()}
15 and \function{os.path.expandvars()}.)
16 \index{filenames!pathname expansion}
18 \begin{funcdesc}{glob}{pathname}
19 Returns a possibly-empty list of path names that match \var{pathname},
20 which must be a string containing a path specification.
21 \var{pathname} can be either absolute (like
22 \file{/usr/src/Python-1.5/Makefile}) or relative (like
23 \file{../../Tools/*/*.gif}), and can contain shell-style wildcards.
24 \end{funcdesc}
26 For example, consider a directory containing only the following files:
27 \file{1.gif}, \file{2.txt}, and \file{card.gif}. \function{glob()}
28 will produce the following results. Notice how any leading components
29 of the path are preserved.
31 \begin{verbatim}
32 >>> import glob
33 >>> glob.glob('./[0-9].*')
34 ['./1.gif', './2.txt']
35 >>> glob.glob('*.gif')
36 ['1.gif', 'card.gif']
37 >>> glob.glob('?.gif')
38 ['1.gif']
39 \end{verbatim}
42 \begin{seealso}
43 \seemodule{fnmatch}{Shell-style filename (not path) expansion}
44 \end{seealso}