| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="module-shutil.html" /> |
| 13 | <link rel="prev" href="module-glob.html" /> |
| 14 | <link rel="parent" href="allos.html" /> |
| 15 | <link rel="next" href="module-shutil.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>6.25 fnmatch -- Unix filename pattern matching</title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="6.24 glob " |
| 25 | href="module-glob.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" |
| 28 | href="allos.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="6.26 shutil " |
| 31 | href="module-shutil.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="module-glob.html">6.24 glob </A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="module-shutil.html">6.26 shutil </A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H1><A NAME="SECTION0082500000000000000000"> |
| 56 | 6.25 <tt class="module">fnmatch</tt> -- |
| 57 | <span class="Unix">Unix</span> filename pattern matching</A> |
| 58 | </H1> |
| 59 | |
| 60 | <P> |
| 61 | <A NAME="module-fnmatch"></A> |
| 62 | |
| 63 | <P> |
| 64 | <a id='l2h-2345' xml:id='l2h-2345'></a> |
| 65 | |
| 66 | <P> |
| 67 | This module provides support for <span class="Unix">Unix</span> shell-style wildcards, which |
| 68 | are <em>not</em> the same as regular expressions (which are documented |
| 69 | in the <tt class="module"><a href="module-re.html">re</a></tt><a id='l2h-2346' xml:id='l2h-2346'></a> module). The special |
| 70 | characters used in shell-style wildcards are: |
| 71 | |
| 72 | <P> |
| 73 | <div class="center"><table class="realtable"> |
| 74 | <thead> |
| 75 | <tr> |
| 76 | <th class="center">Pattern</th> |
| 77 | <th class="left" >Meaning</th> |
| 78 | </tr> |
| 79 | </thead> |
| 80 | <tbody> |
| 81 | <tr><td class="center" valign="baseline"><code>*</code></td> |
| 82 | <td class="left" >matches everything</td></tr> |
| 83 | <tr><td class="center" valign="baseline"><code>?</code></td> |
| 84 | <td class="left" >matches any single character</td></tr> |
| 85 | <tr><td class="center" valign="baseline"><code>[<var>seq</var>]</code></td> |
| 86 | <td class="left" >matches any character in <var>seq</var></td></tr> |
| 87 | <tr><td class="center" valign="baseline"><code>[!<var>seq</var>]</code></td> |
| 88 | <td class="left" >matches any character not in <var>seq</var></td></tr></tbody> |
| 89 | </table></div> |
| 90 | |
| 91 | <P> |
| 92 | Note that the filename separator (<code>'/'</code> on <span class="Unix">Unix</span>) is <em>not</em> |
| 93 | special to this module. See module |
| 94 | <tt class="module"><a href="module-glob.html">glob</a></tt><a id='l2h-2347' xml:id='l2h-2347'></a> for pathname expansion |
| 95 | (<tt class="module"><a href="module-glob.html">glob</a></tt> uses <tt class="function">fnmatch()</tt> to match pathname |
| 96 | segments). Similarly, filenames starting with a period are |
| 97 | not special for this module, and are matched by the <code>*</code> and |
| 98 | <code>?</code> patterns. |
| 99 | |
| 100 | <P> |
| 101 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 102 | <td><nobr><b><tt id='l2h-2342' xml:id='l2h-2342' class="function">fnmatch</tt></b>(</nobr></td> |
| 103 | <td><var>filename, pattern</var>)</td></tr></table></dt> |
| 104 | <dd> |
| 105 | Test whether the <var>filename</var> string matches the <var>pattern</var> |
| 106 | string, returning true or false. If the operating system is |
| 107 | case-insensitive, then both parameters will be normalized to all |
| 108 | lower- or upper-case before the comparison is performed. If you |
| 109 | require a case-sensitive comparison regardless of whether that's |
| 110 | standard for your operating system, use <tt class="function">fnmatchcase()</tt> |
| 111 | instead. |
| 112 | </dl> |
| 113 | |
| 114 | <P> |
| 115 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 116 | <td><nobr><b><tt id='l2h-2343' xml:id='l2h-2343' class="function">fnmatchcase</tt></b>(</nobr></td> |
| 117 | <td><var>filename, pattern</var>)</td></tr></table></dt> |
| 118 | <dd> |
| 119 | Test whether <var>filename</var> matches <var>pattern</var>, returning true or |
| 120 | false; the comparison is case-sensitive. |
| 121 | </dl> |
| 122 | |
| 123 | <P> |
| 124 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 125 | <td><nobr><b><tt id='l2h-2344' xml:id='l2h-2344' class="function">filter</tt></b>(</nobr></td> |
| 126 | <td><var>names, pattern</var>)</td></tr></table></dt> |
| 127 | <dd> |
| 128 | Return the subset of the list of <var>names</var> that match <var>pattern</var>. |
| 129 | It is the same as <code>[n for n in names if fnmatch(n, pattern)]</code>, but |
| 130 | implemented more efficiently. |
| 131 | |
| 132 | <span class="versionnote">New in version 2.2.</span> |
| 133 | |
| 134 | </dl> |
| 135 | |
| 136 | <P> |
| 137 | <div class="seealso"> |
| 138 | <p class="heading">See Also:</p> |
| 139 | |
| 140 | <dl compact="compact" class="seemodule"> |
| 141 | <dt>Module <b><tt class="module"><a href="module-glob.html">glob</a></tt>:</b> |
| 142 | <dd><span class="Unix">Unix</span> shell-style path expansion. |
| 143 | </dl> |
| 144 | </div> |
| 145 | |
| 146 | <DIV CLASS="navigation"> |
| 147 | <div class='online-navigation'> |
| 148 | <p></p><hr /> |
| 149 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 150 | <tr> |
| 151 | <td class='online-navigation'><a rel="prev" title="6.24 glob " |
| 152 | href="module-glob.html"><img src='../icons/previous.png' |
| 153 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 154 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" |
| 155 | href="allos.html"><img src='../icons/up.png' |
| 156 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 157 | <td class='online-navigation'><a rel="next" title="6.26 shutil " |
| 158 | href="module-shutil.html"><img src='../icons/next.png' |
| 159 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 160 | <td align="center" width="100%">Python Library Reference</td> |
| 161 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 162 | href="contents.html"><img src='../icons/contents.png' |
| 163 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 164 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 165 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 166 | <td class='online-navigation'><a rel="index" title="Index" |
| 167 | href="genindex.html"><img src='../icons/index.png' |
| 168 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 169 | </tr></table> |
| 170 | <div class='online-navigation'> |
| 171 | <b class="navlabel">Previous:</b> |
| 172 | <a class="sectref" rel="prev" href="module-glob.html">6.24 glob </A> |
| 173 | <b class="navlabel">Up:</b> |
| 174 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> |
| 175 | <b class="navlabel">Next:</b> |
| 176 | <a class="sectref" rel="next" href="module-shutil.html">6.26 shutil </A> |
| 177 | </div> |
| 178 | </div> |
| 179 | <hr /> |
| 180 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 181 | </DIV> |
| 182 | <!--End of Navigation Panel--> |
| 183 | <ADDRESS> |
| 184 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 185 | </ADDRESS> |
| 186 | </BODY> |
| 187 | </HTML> |