📄 module-filecmp.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.7 filecmp -- File and Directory Comparisons</title>
<META NAME="description" CONTENT="6.7 filecmp -- File and Directory Comparisons">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-popen2.html" tppabs="http://www.python.org/doc/current/lib/module-popen2.html">
<LINK REL="previous" href="module-statvfs.html" tppabs="http://www.python.org/doc/current/lib/module-statvfs.html">
<LINK REL="up" href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html">
<LINK REL="next" href="dircmp-objects.html" tppabs="http://www.python.org/doc/current/lib/dircmp-objects.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-statvfs.html" tppabs="http://www.python.org/doc/current/lib/module-statvfs.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="dircmp-objects.html" tppabs="http://www.python.org/doc/current/lib/dircmp-objects.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="module-statvfs.html" tppabs="http://www.python.org/doc/current/lib/module-statvfs.html">6.6 statvfs </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="dircmp-objects.html" tppabs="http://www.python.org/doc/current/lib/dircmp-objects.html">6.7.1 The dircmp class</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION008700000000000000000">
6.7 <tt class="module">filecmp</tt> --
File and Directory Comparisons</A>
</H1>
<P>
<P>
The <tt class="module">filecmp</tt> module defines functions to compare files and directories,
with various optional time/correctness trade-offs.
<P>
The <tt class="module">filecmp</tt> module defines the following function:
<P>
<dl><dt><b><a name='l2h-1099'><tt class='function'>cmp</tt></a></b> (<var>f1, f2</var><big>[</big><var>, shallow</var><big>[</big><var>, use_statcache</var><big>]</big><big>]</big>)
<dd>
Compare the files named <var>f1</var> and <var>f2</var>, returning <code>1</code> if
they seem equal, <code>0</code> otherwise.
<P>
Unless <var>shallow</var> is given and is false, files with identical
<tt class="function">os.stat()</tt> signatures are taken to be equal. If
<var>use_statcache</var> is given and is true,
<tt class="function">statcache.stat()</tt> will be called rather then
<tt class="function">os.stat()</tt>; the default is to use <tt class="function">os.stat()</tt>.
<P>
Files that were compared using this function will not be compared again
unless their <tt class="function">os.stat()</tt> signature changes. Note that using
<var>use_statcache</var> true will cause the cache invalidation mechanism to
fail -- the stale stat value will be used from <tt class='module'><a href="module-statcache.html" tppabs="http://www.python.org/doc/current/lib/module-statcache.html">statcache</a></tt>'s
cache.
<P>
Note that no external programs are called from this function, giving it
portability and efficiency.
</dl>
<P>
<dl><dt><b><a name='l2h-1100'><tt class='function'>cmpfiles</tt></a></b> (<var>dir1, dir2, common</var><big>[</big><var>,
shallow</var><big>[</big><var>, use_statcache</var><big>]</big><big>]</big>)
<dd>
Returns three lists of file names: <var>match</var>, <var>mismatch</var>,
<var>errors</var>. <var>match</var> contains the list of files match in both
directories, <var>mismatch</var> includes the names of those that don't,
and <var>errros</var> lists the names of files which could not be
compared. Files may be listed in <var>errors</var> because the user may
lack permission to read them or many other reasons, but always that
the comparison could not be done for some reason.
<P>
The <var>shallow</var> and <var>use_statcache</var> parameters have the same
meanings and default values as for <tt class="function">filecmp.cmp()</tt>.
</dl>
<P>
Example:
<P>
<dl><dd><pre class="verbatim">
>>> import filecmp
>>> filecmp.cmp('libundoc.tex', 'libundoc.tex')
1
>>> filecmp.cmp('libundoc.tex', 'lib.tex')
0
</pre></dl>
<P>
<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
<UL>
<LI><A NAME="tex2html2324"
href="dircmp-objects.html" tppabs="http://www.python.org/doc/current/lib/dircmp-objects.html">6.7.1 The <tt class="class">dircmp</tt> class </A>
</UL>
<!--End of Table of Child-Links-->
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-statvfs.html" tppabs="http://www.python.org/doc/current/lib/module-statvfs.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="dircmp-objects.html" tppabs="http://www.python.org/doc/current/lib/dircmp-objects.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="module-statvfs.html" tppabs="http://www.python.org/doc/current/lib/module-statvfs.html">6.6 statvfs </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="dircmp-objects.html" tppabs="http://www.python.org/doc/current/lib/dircmp-objects.html">6.7.1 The dircmp class</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 + -