Commit | Line | Data |
---|---|---|
920dae64 AT |
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-dircache.html" /> | |
13 | <link rel="prev" href="module-os.html" /> | |
14 | <link rel="parent" href="allos.html" /> | |
15 | <link rel="next" href="module-dircache.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.2 os.path -- Common pathname manipulations</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.1.7 Miscellaneous Functions" | |
25 | href="os-miscfunc.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.3 dircache " | |
31 | href="module-dircache.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="os-miscfunc.html">6.1.7 Miscellaneous Functions</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-dircache.html">6.3 dircache </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION008200000000000000000"> | |
56 | 6.2 <tt class="module">os.path</tt> -- | |
57 | Common pathname manipulations</A> | |
58 | </H1> | |
59 | <A NAME="module-os.path"></A> | |
60 | <P> | |
61 | ||
62 | <P> | |
63 | This module implements some useful functions on pathnames. | |
64 | <a id='l2h-1765' xml:id='l2h-1765'></a> | |
65 | ||
66 | <P> | |
67 | <span class="warning"><b class="label">Warning:</b> | |
68 | On Windows, many of these functions do not properly | |
69 | support UNC pathnames. <tt class="function">splitunc()</tt> and <tt class="function">ismount()</tt> | |
70 | do handle them correctly.</span> | |
71 | ||
72 | <P> | |
73 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
74 | <td><nobr><b><tt id='l2h-1735' xml:id='l2h-1735' class="function">abspath</tt></b>(</nobr></td> | |
75 | <td><var>path</var>)</td></tr></table></dt> | |
76 | <dd> | |
77 | Return a normalized absolutized version of the pathname <var>path</var>. | |
78 | On most platforms, this is equivalent to | |
79 | <code>normpath(join(os.getcwd(), <var>path</var>))</code>. | |
80 | ||
81 | <span class="versionnote">New in version 1.5.2.</span> | |
82 | ||
83 | </dl> | |
84 | ||
85 | <P> | |
86 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
87 | <td><nobr><b><tt id='l2h-1736' xml:id='l2h-1736' class="function">basename</tt></b>(</nobr></td> | |
88 | <td><var>path</var>)</td></tr></table></dt> | |
89 | <dd> | |
90 | Return the base name of pathname <var>path</var>. This is the second half | |
91 | of the pair returned by <code>split(<var>path</var>)</code>. Note that the | |
92 | result of this function is different from the | |
93 | <span class="Unix">Unix</span> <b class="program">basename</b> program; where <b class="program">basename</b> for | |
94 | <code>'/foo/bar/'</code> returns <code>'bar'</code>, the <tt class="function">basename()</tt> | |
95 | function returns an empty string (<code>''</code>). | |
96 | </dl> | |
97 | ||
98 | <P> | |
99 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
100 | <td><nobr><b><tt id='l2h-1737' xml:id='l2h-1737' class="function">commonprefix</tt></b>(</nobr></td> | |
101 | <td><var>list</var>)</td></tr></table></dt> | |
102 | <dd> | |
103 | Return the longest path prefix (taken character-by-character) that is a | |
104 | prefix of all paths in | |
105 | <var>list</var>. If <var>list</var> is empty, return the empty string | |
106 | (<code>''</code>). Note that this may return invalid paths because it works a | |
107 | character at a time. | |
108 | </dl> | |
109 | ||
110 | <P> | |
111 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
112 | <td><nobr><b><tt id='l2h-1738' xml:id='l2h-1738' class="function">dirname</tt></b>(</nobr></td> | |
113 | <td><var>path</var>)</td></tr></table></dt> | |
114 | <dd> | |
115 | Return the directory name of pathname <var>path</var>. This is the first | |
116 | half of the pair returned by <code>split(<var>path</var>)</code>. | |
117 | </dl> | |
118 | ||
119 | <P> | |
120 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
121 | <td><nobr><b><tt id='l2h-1739' xml:id='l2h-1739' class="function">exists</tt></b>(</nobr></td> | |
122 | <td><var>path</var>)</td></tr></table></dt> | |
123 | <dd> | |
124 | Return <code>True</code> if <var>path</var> refers to an existing path. | |
125 | Returns <code>False</code> for broken symbolic links. | |
126 | </dl> | |
127 | ||
128 | <P> | |
129 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
130 | <td><nobr><b><tt id='l2h-1740' xml:id='l2h-1740' class="function">lexists</tt></b>(</nobr></td> | |
131 | <td><var>path</var>)</td></tr></table></dt> | |
132 | <dd> | |
133 | Return <code>True</code> if <var>path</var> refers to an existing path. | |
134 | Returns <code>True</code> for broken symbolic links. | |
135 | Equivalent to <tt class="function">exists()</tt> on platforms lacking | |
136 | <tt class="function">os.lstat()</tt>. | |
137 | ||
138 | <span class="versionnote">New in version 2.4.</span> | |
139 | ||
140 | </dl> | |
141 | ||
142 | <P> | |
143 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
144 | <td><nobr><b><tt id='l2h-1741' xml:id='l2h-1741' class="function">expanduser</tt></b>(</nobr></td> | |
145 | <td><var>path</var>)</td></tr></table></dt> | |
146 | <dd> | |
147 | On <span class="Unix">Unix</span>, return the argument with an initial component of "<tt class="samp">~</tt>" or | |
148 | "<tt class="samp">~<var>user</var></tt>" replaced by that <var>user</var>'s home directory. | |
149 | An initial "<tt class="samp">~</tt>" is replaced by the environment variable | |
150 | <a class="envvar" id='l2h-1766' xml:id='l2h-1766'>HOME</a> if it is set; otherwise the current user's home directory | |
151 | is looked up in the password directory through the built-in module | |
152 | <tt class="module"><a href="module-pwd.html">pwd</a></tt><a id='l2h-1767' xml:id='l2h-1767'></a>. | |
153 | An initial "<tt class="samp">~<var>user</var></tt>" is looked up directly in the | |
154 | password directory. | |
155 | ||
156 | <P> | |
157 | On Windows, only "<tt class="samp">~</tt>" is supported; it is replaced by the | |
158 | environment variable <a class="envvar" id='l2h-1768' xml:id='l2h-1768'>HOME</a> or by a combination of | |
159 | <a class="envvar" id='l2h-1769' xml:id='l2h-1769'>HOMEDRIVE</a> and <a class="envvar" id='l2h-1770' xml:id='l2h-1770'>HOMEPATH</a>. | |
160 | ||
161 | <P> | |
162 | If the expansion fails or if the | |
163 | path does not begin with a tilde, the path is returned unchanged. | |
164 | </dl> | |
165 | ||
166 | <P> | |
167 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
168 | <td><nobr><b><tt id='l2h-1742' xml:id='l2h-1742' class="function">expandvars</tt></b>(</nobr></td> | |
169 | <td><var>path</var>)</td></tr></table></dt> | |
170 | <dd> | |
171 | Return the argument with environment variables expanded. Substrings | |
172 | of the form "<tt class="samp">$<var>name</var></tt>" or "<tt class="samp">${<var>name</var>}</tt>" are | |
173 | replaced by the value of environment variable <var>name</var>. Malformed | |
174 | variable names and references to non-existing variables are left | |
175 | unchanged. | |
176 | </dl> | |
177 | ||
178 | <P> | |
179 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
180 | <td><nobr><b><tt id='l2h-1743' xml:id='l2h-1743' class="function">getatime</tt></b>(</nobr></td> | |
181 | <td><var>path</var>)</td></tr></table></dt> | |
182 | <dd> | |
183 | Return the time of last access of <var>path</var>. The return | |
184 | value is a number giving the number of seconds since the epoch (see the | |
185 | <tt class="module"><a href="module-time.html">time</a></tt> module). Raise <tt class="exception">os.error</tt> if the file does | |
186 | not exist or is inaccessible. | |
187 | ||
188 | <span class="versionnote">New in version 1.5.2.</span> | |
189 | ||
190 | <span class="versionnote">Changed in version 2.3: | |
191 | If <tt class="function">os.stat_float_times()</tt> returns True, the result is a floating point number.</span> | |
192 | ||
193 | </dl> | |
194 | ||
195 | <P> | |
196 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
197 | <td><nobr><b><tt id='l2h-1744' xml:id='l2h-1744' class="function">getmtime</tt></b>(</nobr></td> | |
198 | <td><var>path</var>)</td></tr></table></dt> | |
199 | <dd> | |
200 | Return the time of last modification of <var>path</var>. The return | |
201 | value is a number giving the number of seconds since the epoch (see the | |
202 | <tt class="module"><a href="module-time.html">time</a></tt> module). Raise <tt class="exception">os.error</tt> if the file does | |
203 | not exist or is inaccessible. | |
204 | ||
205 | <span class="versionnote">New in version 1.5.2.</span> | |
206 | ||
207 | <span class="versionnote">Changed in version 2.3: | |
208 | If <tt class="function">os.stat_float_times()</tt> returns True, the result is a floating point number.</span> | |
209 | ||
210 | </dl> | |
211 | ||
212 | <P> | |
213 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
214 | <td><nobr><b><tt id='l2h-1745' xml:id='l2h-1745' class="function">getctime</tt></b>(</nobr></td> | |
215 | <td><var>path</var>)</td></tr></table></dt> | |
216 | <dd> | |
217 | Return the system's ctime which, on some systems (like <span class="Unix">Unix</span>) is the | |
218 | time of the last change, and, on others (like Windows), is the | |
219 | creation time for <var>path</var>. The return | |
220 | value is a number giving the number of seconds since the epoch (see the | |
221 | <tt class="module"><a href="module-time.html">time</a></tt> module). Raise <tt class="exception">os.error</tt> if the file does | |
222 | not exist or is inaccessible. | |
223 | ||
224 | <span class="versionnote">New in version 2.3.</span> | |
225 | ||
226 | </dl> | |
227 | ||
228 | <P> | |
229 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
230 | <td><nobr><b><tt id='l2h-1746' xml:id='l2h-1746' class="function">getsize</tt></b>(</nobr></td> | |
231 | <td><var>path</var>)</td></tr></table></dt> | |
232 | <dd> | |
233 | Return the size, in bytes, of <var>path</var>. Raise | |
234 | <tt class="exception">os.error</tt> if the file does not exist or is inaccessible. | |
235 | ||
236 | <span class="versionnote">New in version 1.5.2.</span> | |
237 | ||
238 | </dl> | |
239 | ||
240 | <P> | |
241 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
242 | <td><nobr><b><tt id='l2h-1747' xml:id='l2h-1747' class="function">isabs</tt></b>(</nobr></td> | |
243 | <td><var>path</var>)</td></tr></table></dt> | |
244 | <dd> | |
245 | Return <code>True</code> if <var>path</var> is an absolute pathname (begins with a | |
246 | slash). | |
247 | </dl> | |
248 | ||
249 | <P> | |
250 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
251 | <td><nobr><b><tt id='l2h-1748' xml:id='l2h-1748' class="function">isfile</tt></b>(</nobr></td> | |
252 | <td><var>path</var>)</td></tr></table></dt> | |
253 | <dd> | |
254 | Return <code>True</code> if <var>path</var> is an existing regular file. This follows | |
255 | symbolic links, so both <tt class="function">islink()</tt> and <tt class="function">isfile()</tt> | |
256 | can be true for the same path. | |
257 | </dl> | |
258 | ||
259 | <P> | |
260 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
261 | <td><nobr><b><tt id='l2h-1749' xml:id='l2h-1749' class="function">isdir</tt></b>(</nobr></td> | |
262 | <td><var>path</var>)</td></tr></table></dt> | |
263 | <dd> | |
264 | Return <code>True</code> if <var>path</var> is an existing directory. This follows | |
265 | symbolic links, so both <tt class="function">islink()</tt> and <tt class="function">isdir()</tt> can | |
266 | be true for the same path. | |
267 | </dl> | |
268 | ||
269 | <P> | |
270 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
271 | <td><nobr><b><tt id='l2h-1750' xml:id='l2h-1750' class="function">islink</tt></b>(</nobr></td> | |
272 | <td><var>path</var>)</td></tr></table></dt> | |
273 | <dd> | |
274 | Return <code>True</code> if <var>path</var> refers to a directory entry that is a | |
275 | symbolic link. Always <code>False</code> if symbolic links are not supported. | |
276 | </dl> | |
277 | ||
278 | <P> | |
279 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
280 | <td><nobr><b><tt id='l2h-1751' xml:id='l2h-1751' class="function">ismount</tt></b>(</nobr></td> | |
281 | <td><var>path</var>)</td></tr></table></dt> | |
282 | <dd> | |
283 | Return <code>True</code> if pathname <var>path</var> is a <i class="dfn">mount point</i>: a point in | |
284 | a file system where a different file system has been mounted. The | |
285 | function checks whether <var>path</var>'s parent, <span class="file"><var>path</var>/..</span>, is | |
286 | on a different device than <var>path</var>, or whether <span class="file"><var>path</var>/..</span> | |
287 | and <var>path</var> point to the same i-node on the same device -- this | |
288 | should detect mount points for all <span class="Unix">Unix</span> and POSIX variants. | |
289 | </dl> | |
290 | ||
291 | <P> | |
292 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
293 | <td><nobr><b><tt id='l2h-1752' xml:id='l2h-1752' class="function">join</tt></b>(</nobr></td> | |
294 | <td><var>path1</var><big>[</big><var>, path2</var><big>[</big><var>, ...</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
295 | <dd> | |
296 | Joins one or more path components intelligently. If any component is | |
297 | an absolute path, all previous components are thrown away, and joining | |
298 | continues. The return value is the concatenation of <var>path1</var>, and | |
299 | optionally <var>path2</var>, etc., with exactly one directory separator | |
300 | (<code>os.sep</code>) inserted between components, unless <var>path2</var> is | |
301 | empty. Note that on Windows, since there is a current directory for | |
302 | each drive, <tt class="function">os.path.join("c:", "foo")</tt> represents a path | |
303 | relative to the current directory on drive <span class="file">C:</span> (<span class="file">c:foo</span>), not | |
304 | <span class="file">c:\\foo</span>. | |
305 | </dl> | |
306 | ||
307 | <P> | |
308 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
309 | <td><nobr><b><tt id='l2h-1753' xml:id='l2h-1753' class="function">normcase</tt></b>(</nobr></td> | |
310 | <td><var>path</var>)</td></tr></table></dt> | |
311 | <dd> | |
312 | Normalize the case of a pathname. On <span class="Unix">Unix</span>, this returns the path | |
313 | unchanged; on case-insensitive filesystems, it converts the path to | |
314 | lowercase. On Windows, it also converts forward slashes to backward | |
315 | slashes. | |
316 | </dl> | |
317 | ||
318 | <P> | |
319 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
320 | <td><nobr><b><tt id='l2h-1754' xml:id='l2h-1754' class="function">normpath</tt></b>(</nobr></td> | |
321 | <td><var>path</var>)</td></tr></table></dt> | |
322 | <dd> | |
323 | Normalize a pathname. This collapses redundant separators and | |
324 | up-level references so that <code>A//B</code>, <code>A/./B</code> and | |
325 | <code>A/foo/../B</code> all become <code>A/B</code>. It does not normalize the | |
326 | case (use <tt class="function">normcase()</tt> for that). On Windows, it converts | |
327 | forward slashes to backward slashes. It should be understood that this may | |
328 | change the meaning of the path if it contains symbolic links! | |
329 | </dl> | |
330 | ||
331 | <P> | |
332 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
333 | <td><nobr><b><tt id='l2h-1755' xml:id='l2h-1755' class="function">realpath</tt></b>(</nobr></td> | |
334 | <td><var>path</var>)</td></tr></table></dt> | |
335 | <dd> | |
336 | Return the canonical path of the specified filename, eliminating any | |
337 | symbolic links encountered in the path. | |
338 | Availability: <span class="Unix">Unix</span>. | |
339 | ||
340 | <span class="versionnote">New in version 2.2.</span> | |
341 | ||
342 | </dl> | |
343 | ||
344 | <P> | |
345 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
346 | <td><nobr><b><tt id='l2h-1756' xml:id='l2h-1756' class="function">samefile</tt></b>(</nobr></td> | |
347 | <td><var>path1, path2</var>)</td></tr></table></dt> | |
348 | <dd> | |
349 | Return <code>True</code> if both pathname arguments refer to the same file or | |
350 | directory (as indicated by device number and i-node number). | |
351 | Raise an exception if a <tt class="function">os.stat()</tt> call on either pathname | |
352 | fails. | |
353 | Availability: Macintosh, <span class="Unix">Unix</span>. | |
354 | </dl> | |
355 | ||
356 | <P> | |
357 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
358 | <td><nobr><b><tt id='l2h-1757' xml:id='l2h-1757' class="function">sameopenfile</tt></b>(</nobr></td> | |
359 | <td><var>fp1, fp2</var>)</td></tr></table></dt> | |
360 | <dd> | |
361 | Return <code>True</code> if the file objects <var>fp1</var> and <var>fp2</var> refer to the | |
362 | same file. The two file objects may represent different file | |
363 | descriptors. | |
364 | Availability: Macintosh, <span class="Unix">Unix</span>. | |
365 | </dl> | |
366 | ||
367 | <P> | |
368 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
369 | <td><nobr><b><tt id='l2h-1758' xml:id='l2h-1758' class="function">samestat</tt></b>(</nobr></td> | |
370 | <td><var>stat1, stat2</var>)</td></tr></table></dt> | |
371 | <dd> | |
372 | Return <code>True</code> if the stat tuples <var>stat1</var> and <var>stat2</var> refer to | |
373 | the same file. These structures may have been returned by | |
374 | <tt class="function">fstat()</tt>, <tt class="function">lstat()</tt>, or <tt class="function">stat()</tt>. This | |
375 | function implements the underlying comparison used by | |
376 | <tt class="function">samefile()</tt> and <tt class="function">sameopenfile()</tt>. | |
377 | Availability: Macintosh, <span class="Unix">Unix</span>. | |
378 | </dl> | |
379 | ||
380 | <P> | |
381 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
382 | <td><nobr><b><tt id='l2h-1759' xml:id='l2h-1759' class="function">split</tt></b>(</nobr></td> | |
383 | <td><var>path</var>)</td></tr></table></dt> | |
384 | <dd> | |
385 | Split the pathname <var>path</var> into a pair, <code>(<var>head</var>, | |
386 | <var>tail</var>)</code> where <var>tail</var> is the last pathname component and | |
387 | <var>head</var> is everything leading up to that. The <var>tail</var> part will | |
388 | never contain a slash; if <var>path</var> ends in a slash, <var>tail</var> will | |
389 | be empty. If there is no slash in <var>path</var>, <var>head</var> will be | |
390 | empty. If <var>path</var> is empty, both <var>head</var> and <var>tail</var> are | |
391 | empty. Trailing slashes are stripped from <var>head</var> unless it is the | |
392 | root (one or more slashes only). In nearly all cases, | |
393 | <code>join(<var>head</var>, <var>tail</var>)</code> equals <var>path</var> (the only | |
394 | exception being when there were multiple slashes separating <var>head</var> | |
395 | from <var>tail</var>). | |
396 | </dl> | |
397 | ||
398 | <P> | |
399 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
400 | <td><nobr><b><tt id='l2h-1760' xml:id='l2h-1760' class="function">splitdrive</tt></b>(</nobr></td> | |
401 | <td><var>path</var>)</td></tr></table></dt> | |
402 | <dd> | |
403 | Split the pathname <var>path</var> into a pair <code>(<var>drive</var>, | |
404 | <var>tail</var>)</code> where <var>drive</var> is either a drive specification or the | |
405 | empty string. On systems which do not use drive specifications, | |
406 | <var>drive</var> will always be the empty string. In all cases, | |
407 | <code><var>drive</var> + <var>tail</var></code> will be the same as <var>path</var>. | |
408 | ||
409 | <span class="versionnote">New in version 1.3.</span> | |
410 | ||
411 | </dl> | |
412 | ||
413 | <P> | |
414 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
415 | <td><nobr><b><tt id='l2h-1761' xml:id='l2h-1761' class="function">splitext</tt></b>(</nobr></td> | |
416 | <td><var>path</var>)</td></tr></table></dt> | |
417 | <dd> | |
418 | Split the pathname <var>path</var> into a pair <code>(<var>root</var>, <var>ext</var>)</code> | |
419 | such that <code><var>root</var> + <var>ext</var> == <var>path</var></code>, | |
420 | and <var>ext</var> is empty or begins with a period and contains | |
421 | at most one period. | |
422 | </dl> | |
423 | ||
424 | <P> | |
425 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
426 | <td><nobr><b><tt id='l2h-1762' xml:id='l2h-1762' class="function">splitunc</tt></b>(</nobr></td> | |
427 | <td><var>path</var>)</td></tr></table></dt> | |
428 | <dd> | |
429 | Split the pathname <var>path</var> into a pair <code>(<var>unc</var>, <var>rest</var>)</code> | |
430 | so that <var>unc</var> is the UNC mount point (such as <code>r'\\host\mount'</code>), | |
431 | if present, and <var>rest</var> the rest of the path (such as | |
432 | <code>r'\path\file.ext'</code>). For paths containing drive letters, <var>unc</var> | |
433 | will always be the empty string. | |
434 | Availability: Windows. | |
435 | </dl> | |
436 | ||
437 | <P> | |
438 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
439 | <td><nobr><b><tt id='l2h-1763' xml:id='l2h-1763' class="function">walk</tt></b>(</nobr></td> | |
440 | <td><var>path, visit, arg</var>)</td></tr></table></dt> | |
441 | <dd> | |
442 | Calls the function <var>visit</var> with arguments | |
443 | <code>(<var>arg</var>, <var>dirname</var>, <var>names</var>)</code> for each directory in the | |
444 | directory tree rooted at <var>path</var> (including <var>path</var> itself, if it | |
445 | is a directory). The argument <var>dirname</var> specifies the visited | |
446 | directory, the argument <var>names</var> lists the files in the directory | |
447 | (gotten from <code>os.listdir(<var>dirname</var>)</code>). | |
448 | The <var>visit</var> function may modify <var>names</var> to | |
449 | influence the set of directories visited below <var>dirname</var>, e.g. to | |
450 | avoid visiting certain parts of the tree. (The object referred to by | |
451 | <var>names</var> must be modified in place, using <tt class="keyword">del</tt> or slice | |
452 | assignment.) | |
453 | ||
454 | <P> | |
455 | <div class="note"><b class="label">Note:</b> | |
456 | Symbolic links to directories are not treated as subdirectories, and | |
457 | that <tt class="function">walk()</tt> therefore will not visit them. To visit linked | |
458 | directories you must identify them with | |
459 | <code>os.path.islink(<var>file</var>)</code> and | |
460 | <code>os.path.isdir(<var>file</var>)</code>, and invoke <tt class="function">walk()</tt> as | |
461 | necessary. | |
462 | </div> | |
463 | ||
464 | <P> | |
465 | <span class="note"><b class="label">Note:</b> | |
466 | The newer <tt class="function"><tt class="module"><a href="module-os.html">os</a></tt>.walk()</tt> generator supplies | |
467 | similar functionality and can be easier to use.</span> | |
468 | </dl> | |
469 | ||
470 | <P> | |
471 | <dl><dt><b><tt id='l2h-1764' xml:id='l2h-1764'>supports_unicode_filenames</tt></b></dt> | |
472 | <dd> | |
473 | True if arbitrary Unicode strings can be used as file names (within | |
474 | limitations imposed by the file system), and if | |
475 | <tt class="function">os.listdir()</tt> returns Unicode strings for a Unicode | |
476 | argument. | |
477 | ||
478 | <span class="versionnote">New in version 2.3.</span> | |
479 | ||
480 | </dd></dl> | |
481 | ||
482 | <DIV CLASS="navigation"> | |
483 | <div class='online-navigation'> | |
484 | <p></p><hr /> | |
485 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
486 | <tr> | |
487 | <td class='online-navigation'><a rel="prev" title="6.1.7 Miscellaneous Functions" | |
488 | href="os-miscfunc.html"><img src='../icons/previous.png' | |
489 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
490 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
491 | href="allos.html"><img src='../icons/up.png' | |
492 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
493 | <td class='online-navigation'><a rel="next" title="6.3 dircache " | |
494 | href="module-dircache.html"><img src='../icons/next.png' | |
495 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
496 | <td align="center" width="100%">Python Library Reference</td> | |
497 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
498 | href="contents.html"><img src='../icons/contents.png' | |
499 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
500 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
501 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
502 | <td class='online-navigation'><a rel="index" title="Index" | |
503 | href="genindex.html"><img src='../icons/index.png' | |
504 | border='0' height='32' alt='Index' width='32' /></A></td> | |
505 | </tr></table> | |
506 | <div class='online-navigation'> | |
507 | <b class="navlabel">Previous:</b> | |
508 | <a class="sectref" rel="prev" href="os-miscfunc.html">6.1.7 Miscellaneous Functions</A> | |
509 | <b class="navlabel">Up:</b> | |
510 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
511 | <b class="navlabel">Next:</b> | |
512 | <a class="sectref" rel="next" href="module-dircache.html">6.3 dircache </A> | |
513 | </div> | |
514 | </div> | |
515 | <hr /> | |
516 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
517 | </DIV> | |
518 | <!--End of Navigation Panel--> | |
519 | <ADDRESS> | |
520 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
521 | </ADDRESS> | |
522 | </BODY> | |
523 | </HTML> |