📄 module-ospath.html
字号:
<P>
<dl><dt><b><a name='l2h-1040'><tt class='function'>isdir</tt></a></b> (<var>path</var>)
<dd>
Return true if <var>path</var> is an existing directory. This follows
symbolic links, so both <tt class="function">islink()</tt> and <tt class="function">isdir()</tt> can
be true for the same path.
</dl>
<P>
<dl><dt><b><a name='l2h-1041'><tt class='function'>islink</tt></a></b> (<var>path</var>)
<dd>
Return true if <var>path</var> refers to a directory entry that is a
symbolic link. Always false if symbolic links are not supported.
</dl>
<P>
<dl><dt><b><a name='l2h-1042'><tt class='function'>ismount</tt></a></b> (<var>path</var>)
<dd>
Return true if pathname <var>path</var> is a <i class="dfn">mount point</i>: a point in
a file system where a different file system has been mounted. The
function checks whether <var>path</var>'s parent, <span class="file"><var>path</var>/..</span>, is
on a different device than <var>path</var>, or whether <span class="file"><var>path</var>/..</span>
and <var>path</var> point to the same i-node on the same device -- this
should detect mount points for all Unix and POSIX variants.
</dl>
<P>
<dl><dt><b><a name='l2h-1043'><tt class='function'>join</tt></a></b> (<var>path1</var><big>[</big><var>, path2</var><big>[</big><var>, ...</var><big>]</big><big>]</big>)
<dd>
Joins one or more path components intelligently. If any component is
an absolute path, all previous components are thrown away, and joining
continues. The return value is the concatenation of <var>path1</var>, and
optionally <var>path2</var>, etc., with exactly one slash (<code>'/'</code>)
inserted between components, unless <var>path</var> is empty.
</dl>
<P>
<dl><dt><b><a name='l2h-1044'><tt class='function'>normcase</tt></a></b> (<var>path</var>)
<dd>
Normalize the case of a pathname. On Unix, this returns the path
unchanged; on case-insensitive filesystems, it converts the path to
lowercase. On Windows, it also converts forward slashes to backward
slashes.
</dl>
<P>
<dl><dt><b><a name='l2h-1045'><tt class='function'>normpath</tt></a></b> (<var>path</var>)
<dd>
Normalize a pathname. This collapses redundant separators and
up-level references, e.g. <code>A//B</code>, <code>A/./B</code> and
<code>A/foo/../B</code> all become <code>A/B</code>. It does not normalize the
case (use <tt class="function">normcase()</tt> for that). On Windows, it converts
forward slashes to backward slashes.
</dl>
<P>
<dl><dt><b><a name='l2h-1046'><tt class='function'>samefile</tt></a></b> (<var>path1, path2</var>)
<dd>
Return true if both pathname arguments refer to the same file or
directory (as indicated by device number and i-node number).
Raise an exception if a <tt class="function">os.stat()</tt> call on either pathname
fails.
Availability: Macintosh, Unix.
</dl>
<P>
<dl><dt><b><a name='l2h-1047'><tt class='function'>sameopenfile</tt></a></b> (<var>fp1, fp2</var>)
<dd>
Return true if the file objects <var>fp1</var> and <var>fp2</var> refer to the
same file. The two file objects may represent different file
descriptors.
Availability: Macintosh, Unix.
</dl>
<P>
<dl><dt><b><a name='l2h-1048'><tt class='function'>samestat</tt></a></b> (<var>stat1, stat2</var>)
<dd>
Return true if the stat tuples <var>stat1</var> and <var>stat2</var> refer to
the same file. These structures may have been returned by
<tt class="function">fstat()</tt>, <tt class="function">lstat()</tt>, or <tt class="function">stat()</tt>. This
function implements the underlying comparison used by
<tt class="function">samefile()</tt> and <tt class="function">sameopenfile()</tt>.
Availability: Macintosh, Unix.
</dl>
<P>
<dl><dt><b><a name='l2h-1049'><tt class='function'>split</tt></a></b> (<var>path</var>)
<dd>
Split the pathname <var>path</var> into a pair, <code>(<var>head</var>,
<var>tail</var>)</code> where <var>tail</var> is the last pathname component and
<var>head</var> is everything leading up to that. The <var>tail</var> part will
never contain a slash; if <var>path</var> ends in a slash, <var>tail</var> will
be empty. If there is no slash in <var>path</var>, <var>head</var> will be
empty. If <var>path</var> is empty, both <var>head</var> and <var>tail</var> are
empty. Trailing slashes are stripped from <var>head</var> unless it is the
root (one or more slashes only). In nearly all cases,
<code>join(<var>head</var>, <var>tail</var>)</code> equals <var>path</var> (the only
exception being when there were multiple slashes separating <var>head</var>
from <var>tail</var>).
</dl>
<P>
<dl><dt><b><a name='l2h-1050'><tt class='function'>splitdrive</tt></a></b> (<var>path</var>)
<dd>
Split the pathname <var>path</var> into a pair <code>(<var>drive</var>,
<var>tail</var>)</code> where <var>drive</var> is either a drive specification or the
empty string. On systems which do not use drive specifications,
<var>drive</var> will always be the empty string. In all cases,
<code><var>drive</var> + <var>tail</var></code> will be the same as <var>path</var>.
</dl>
<P>
<dl><dt><b><a name='l2h-1051'><tt class='function'>splitext</tt></a></b> (<var>path</var>)
<dd>
Split the pathname <var>path</var> into a pair <code>(<var>root</var>, <var>ext</var>)</code>
such that <code><var>root</var> + <var>ext</var> == <var>path</var></code>,
and <var>ext</var> is empty or begins with a period and contains
at most one period.
</dl>
<P>
<dl><dt><b><a name='l2h-1052'><tt class='function'>walk</tt></a></b> (<var>path, visit, arg</var>)
<dd>
Calls the function <var>visit</var> with arguments
<code>(<var>arg</var>, <var>dirname</var>, <var>names</var>)</code> for each directory in the
directory tree rooted at <var>path</var> (including <var>path</var> itself, if it
is a directory). The argument <var>dirname</var> specifies the visited
directory, the argument <var>names</var> lists the files in the directory
(gotten from <code>os.listdir(<var>dirname</var>)</code>).
The <var>visit</var> function may modify <var>names</var> to
influence the set of directories visited below <var>dirname</var>, e.g., to
avoid visiting certain parts of the tree. (The object referred to by
<var>names</var> must be modified in place, using <tt class="keyword">del</tt> or slice
assignment.)
</dl>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="os-path.html" tppabs="http://www.python.org/doc/current/lib/os-path.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-dircache.html" tppabs="http://www.python.org/doc/current/lib/module-dircache.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="os-path.html" tppabs="http://www.python.org/doc/current/lib/os-path.html">6.1.6 Miscellaneous System Information</A>
<b class="navlabel">Up:</b> <a class="sectref" href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html">6. Generic Operating System</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-dircache.html" tppabs="http://www.python.org/doc/current/lib/module-dircache.html">6.3 dircache </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -