gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

539 lines
35KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="filecmp — File and Directory Comparisons" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/filecmp.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/filecmp.py The filecmp module defines functions to compare files and directories, with various optional time/correctness trade-offs. For comparing files, see also the difflib modul..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/filecmp.py The filecmp module defines functions to compare files and directories, with various optional time/correctness trade-offs. For comparing files, see also the difflib modul..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>filecmp — File and Directory Comparisons &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="tempfile — Generate temporary files and directories" href="tempfile.html" />
  33. <link rel="prev" title="stat — Interpreting stat() results" href="stat.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/filecmp.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> — File and Directory Comparisons</a><ul>
  86. <li><a class="reference internal" href="#the-dircmp-class">The <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code> class</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div>
  91. <div>
  92. <h4>Previous topic</h4>
  93. <p class="topless"><a href="stat.html"
  94. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code> — Interpreting <code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code> results</a></p>
  95. </div>
  96. <div>
  97. <h4>Next topic</h4>
  98. <p class="topless"><a href="tempfile.html"
  99. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tempfile</span></code> — Generate temporary files and directories</a></p>
  100. </div>
  101. <div role="note" aria-label="source link">
  102. <h3>This Page</h3>
  103. <ul class="this-page-menu">
  104. <li><a href="../bugs.html">Report a Bug</a></li>
  105. <li>
  106. <a href="https://github.com/python/cpython/blob/main/Doc/library/filecmp.rst"
  107. rel="nofollow">Show Source
  108. </a>
  109. </li>
  110. </ul>
  111. </div>
  112. </nav>
  113. </div>
  114. </div>
  115. <div class="related" role="navigation" aria-label="related navigation">
  116. <h3>Navigation</h3>
  117. <ul>
  118. <li class="right" style="margin-right: 10px">
  119. <a href="../genindex.html" title="General Index"
  120. accesskey="I">index</a></li>
  121. <li class="right" >
  122. <a href="../py-modindex.html" title="Python Module Index"
  123. >modules</a> |</li>
  124. <li class="right" >
  125. <a href="tempfile.html" title="tempfile — Generate temporary files and directories"
  126. accesskey="N">next</a> |</li>
  127. <li class="right" >
  128. <a href="stat.html" title="stat — Interpreting stat() results"
  129. accesskey="P">previous</a> |</li>
  130. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  131. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  132. <li class="switchers">
  133. <div class="language_switcher_placeholder"></div>
  134. <div class="version_switcher_placeholder"></div>
  135. </li>
  136. <li>
  137. </li>
  138. <li id="cpython-language-and-version">
  139. <a href="../index.html">3.12.3 Documentation</a> &#187;
  140. </li>
  141. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  142. <li class="nav-item nav-item-2"><a href="filesys.html" accesskey="U">File and Directory Access</a> &#187;</li>
  143. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> — File and Directory Comparisons</a></li>
  144. <li class="right">
  145. <div class="inline-search" role="search">
  146. <form class="inline-search" action="../search.html" method="get">
  147. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  148. <input type="submit" value="Go" />
  149. </form>
  150. </div>
  151. |
  152. </li>
  153. <li class="right">
  154. <label class="theme-selector-label">
  155. Theme
  156. <select class="theme-selector" oninput="activateTheme(this.value)">
  157. <option value="auto" selected>Auto</option>
  158. <option value="light">Light</option>
  159. <option value="dark">Dark</option>
  160. </select>
  161. </label> |</li>
  162. </ul>
  163. </div>
  164. <div class="document">
  165. <div class="documentwrapper">
  166. <div class="bodywrapper">
  167. <div class="body" role="main">
  168. <section id="module-filecmp">
  169. <span id="filecmp-file-and-directory-comparisons"></span><h1><a class="reference internal" href="#module-filecmp" title="filecmp: Compare files efficiently."><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code></a> — File and Directory Comparisons<a class="headerlink" href="#module-filecmp" title="Link to this heading">¶</a></h1>
  170. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/filecmp.py">Lib/filecmp.py</a></p>
  171. <hr class="docutils" />
  172. <p>The <a class="reference internal" href="#module-filecmp" title="filecmp: Compare files efficiently."><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code></a> module defines functions to compare files and directories,
  173. with various optional time/correctness trade-offs. For comparing files,
  174. see also the <a class="reference internal" href="difflib.html#module-difflib" title="difflib: Helpers for computing differences between objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">difflib</span></code></a> module.</p>
  175. <p>The <a class="reference internal" href="#module-filecmp" title="filecmp: Compare files efficiently."><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code></a> module defines the following functions:</p>
  176. <dl class="py function">
  177. <dt class="sig sig-object py" id="filecmp.cmp">
  178. <span class="sig-prename descclassname"><span class="pre">filecmp.</span></span><span class="sig-name descname"><span class="pre">cmp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">f2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shallow</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#filecmp.cmp" title="Link to this definition">¶</a></dt>
  179. <dd><p>Compare the files named <em>f1</em> and <em>f2</em>, returning <code class="docutils literal notranslate"><span class="pre">True</span></code> if they seem equal,
  180. <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p>
  181. <p>If <em>shallow</em> is true and the <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> signatures (file type, size, and
  182. modification time) of both files are identical, the files are taken to be
  183. equal.</p>
  184. <p>Otherwise, the files are treated as different if their sizes or contents differ.</p>
  185. <p>Note that no external programs are called from this function, giving it
  186. portability and efficiency.</p>
  187. <p>This function uses a cache for past comparisons and the results,
  188. with cache entries invalidated if the <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> information for the
  189. file changes. The entire cache may be cleared using <a class="reference internal" href="#filecmp.clear_cache" title="filecmp.clear_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear_cache()</span></code></a>.</p>
  190. </dd></dl>
  191. <dl class="py function">
  192. <dt class="sig sig-object py" id="filecmp.cmpfiles">
  193. <span class="sig-prename descclassname"><span class="pre">filecmp.</span></span><span class="sig-name descname"><span class="pre">cmpfiles</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dir1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">common</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shallow</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#filecmp.cmpfiles" title="Link to this definition">¶</a></dt>
  194. <dd><p>Compare the files in the two directories <em>dir1</em> and <em>dir2</em> whose names are
  195. given by <em>common</em>.</p>
  196. <p>Returns three lists of file names: <em>match</em>, <em>mismatch</em>,
  197. <em>errors</em>. <em>match</em> contains the list of files that match, <em>mismatch</em> contains
  198. the names of those that don’t, and <em>errors</em> lists the names of files which
  199. could not be compared. Files are listed in <em>errors</em> if they don’t exist in
  200. one of the directories, the user lacks permission to read them or if the
  201. comparison could not be done for some other reason.</p>
  202. <p>The <em>shallow</em> parameter has the same meaning and default value as for
  203. <a class="reference internal" href="#filecmp.cmp" title="filecmp.cmp"><code class="xref py py-func docutils literal notranslate"><span class="pre">filecmp.cmp()</span></code></a>.</p>
  204. <p>For example, <code class="docutils literal notranslate"><span class="pre">cmpfiles('a',</span> <span class="pre">'b',</span> <span class="pre">['c',</span> <span class="pre">'d/e'])</span></code> will compare <code class="docutils literal notranslate"><span class="pre">a/c</span></code> with
  205. <code class="docutils literal notranslate"><span class="pre">b/c</span></code> and <code class="docutils literal notranslate"><span class="pre">a/d/e</span></code> with <code class="docutils literal notranslate"><span class="pre">b/d/e</span></code>. <code class="docutils literal notranslate"><span class="pre">'c'</span></code> and <code class="docutils literal notranslate"><span class="pre">'d/e'</span></code> will each be in
  206. one of the three returned lists.</p>
  207. </dd></dl>
  208. <dl class="py function">
  209. <dt class="sig sig-object py" id="filecmp.clear_cache">
  210. <span class="sig-prename descclassname"><span class="pre">filecmp.</span></span><span class="sig-name descname"><span class="pre">clear_cache</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#filecmp.clear_cache" title="Link to this definition">¶</a></dt>
  211. <dd><p>Clear the filecmp cache. This may be useful if a file is compared so quickly
  212. after it is modified that it is within the mtime resolution of
  213. the underlying filesystem.</p>
  214. <div class="versionadded">
  215. <p><span class="versionmodified added">New in version 3.4.</span></p>
  216. </div>
  217. </dd></dl>
  218. <section id="the-dircmp-class">
  219. <span id="dircmp-objects"></span><h2>The <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a> class<a class="headerlink" href="#the-dircmp-class" title="Link to this heading">¶</a></h2>
  220. <dl class="py class">
  221. <dt class="sig sig-object py" id="filecmp.dircmp">
  222. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">filecmp.</span></span><span class="sig-name descname"><span class="pre">dircmp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ignore</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hide</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#filecmp.dircmp" title="Link to this definition">¶</a></dt>
  223. <dd><p>Construct a new directory comparison object, to compare the directories <em>a</em>
  224. and <em>b</em>. <em>ignore</em> is a list of names to ignore, and defaults to
  225. <a class="reference internal" href="#filecmp.DEFAULT_IGNORES" title="filecmp.DEFAULT_IGNORES"><code class="xref py py-const docutils literal notranslate"><span class="pre">filecmp.DEFAULT_IGNORES</span></code></a>. <em>hide</em> is a list of names to hide, and
  226. defaults to <code class="docutils literal notranslate"><span class="pre">[os.curdir,</span> <span class="pre">os.pardir]</span></code>.</p>
  227. <p>The <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a> class compares files by doing <em>shallow</em> comparisons
  228. as described for <a class="reference internal" href="#filecmp.cmp" title="filecmp.cmp"><code class="xref py py-func docutils literal notranslate"><span class="pre">filecmp.cmp()</span></code></a>.</p>
  229. <p>The <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a> class provides the following methods:</p>
  230. <dl class="py method">
  231. <dt class="sig sig-object py" id="filecmp.dircmp.report">
  232. <span class="sig-name descname"><span class="pre">report</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#filecmp.dircmp.report" title="Link to this definition">¶</a></dt>
  233. <dd><p>Print (to <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a>) a comparison between <em>a</em> and <em>b</em>.</p>
  234. </dd></dl>
  235. <dl class="py method">
  236. <dt class="sig sig-object py" id="filecmp.dircmp.report_partial_closure">
  237. <span class="sig-name descname"><span class="pre">report_partial_closure</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#filecmp.dircmp.report_partial_closure" title="Link to this definition">¶</a></dt>
  238. <dd><p>Print a comparison between <em>a</em> and <em>b</em> and common immediate
  239. subdirectories.</p>
  240. </dd></dl>
  241. <dl class="py method">
  242. <dt class="sig sig-object py" id="filecmp.dircmp.report_full_closure">
  243. <span class="sig-name descname"><span class="pre">report_full_closure</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#filecmp.dircmp.report_full_closure" title="Link to this definition">¶</a></dt>
  244. <dd><p>Print a comparison between <em>a</em> and <em>b</em> and common subdirectories
  245. (recursively).</p>
  246. </dd></dl>
  247. <p>The <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a> class offers a number of interesting attributes that may be
  248. used to get various bits of information about the directory trees being
  249. compared.</p>
  250. <p>Note that via <a class="reference internal" href="../reference/datamodel.html#object.__getattr__" title="object.__getattr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getattr__()</span></code></a> hooks, all attributes are computed lazily,
  251. so there is no speed penalty if only those attributes which are lightweight
  252. to compute are used.</p>
  253. <dl class="py attribute">
  254. <dt class="sig sig-object py" id="filecmp.dircmp.left">
  255. <span class="sig-name descname"><span class="pre">left</span></span><a class="headerlink" href="#filecmp.dircmp.left" title="Link to this definition">¶</a></dt>
  256. <dd><p>The directory <em>a</em>.</p>
  257. </dd></dl>
  258. <dl class="py attribute">
  259. <dt class="sig sig-object py" id="filecmp.dircmp.right">
  260. <span class="sig-name descname"><span class="pre">right</span></span><a class="headerlink" href="#filecmp.dircmp.right" title="Link to this definition">¶</a></dt>
  261. <dd><p>The directory <em>b</em>.</p>
  262. </dd></dl>
  263. <dl class="py attribute">
  264. <dt class="sig sig-object py" id="filecmp.dircmp.left_list">
  265. <span class="sig-name descname"><span class="pre">left_list</span></span><a class="headerlink" href="#filecmp.dircmp.left_list" title="Link to this definition">¶</a></dt>
  266. <dd><p>Files and subdirectories in <em>a</em>, filtered by <em>hide</em> and <em>ignore</em>.</p>
  267. </dd></dl>
  268. <dl class="py attribute">
  269. <dt class="sig sig-object py" id="filecmp.dircmp.right_list">
  270. <span class="sig-name descname"><span class="pre">right_list</span></span><a class="headerlink" href="#filecmp.dircmp.right_list" title="Link to this definition">¶</a></dt>
  271. <dd><p>Files and subdirectories in <em>b</em>, filtered by <em>hide</em> and <em>ignore</em>.</p>
  272. </dd></dl>
  273. <dl class="py attribute">
  274. <dt class="sig sig-object py" id="filecmp.dircmp.common">
  275. <span class="sig-name descname"><span class="pre">common</span></span><a class="headerlink" href="#filecmp.dircmp.common" title="Link to this definition">¶</a></dt>
  276. <dd><p>Files and subdirectories in both <em>a</em> and <em>b</em>.</p>
  277. </dd></dl>
  278. <dl class="py attribute">
  279. <dt class="sig sig-object py" id="filecmp.dircmp.left_only">
  280. <span class="sig-name descname"><span class="pre">left_only</span></span><a class="headerlink" href="#filecmp.dircmp.left_only" title="Link to this definition">¶</a></dt>
  281. <dd><p>Files and subdirectories only in <em>a</em>.</p>
  282. </dd></dl>
  283. <dl class="py attribute">
  284. <dt class="sig sig-object py" id="filecmp.dircmp.right_only">
  285. <span class="sig-name descname"><span class="pre">right_only</span></span><a class="headerlink" href="#filecmp.dircmp.right_only" title="Link to this definition">¶</a></dt>
  286. <dd><p>Files and subdirectories only in <em>b</em>.</p>
  287. </dd></dl>
  288. <dl class="py attribute">
  289. <dt class="sig sig-object py" id="filecmp.dircmp.common_dirs">
  290. <span class="sig-name descname"><span class="pre">common_dirs</span></span><a class="headerlink" href="#filecmp.dircmp.common_dirs" title="Link to this definition">¶</a></dt>
  291. <dd><p>Subdirectories in both <em>a</em> and <em>b</em>.</p>
  292. </dd></dl>
  293. <dl class="py attribute">
  294. <dt class="sig sig-object py" id="filecmp.dircmp.common_files">
  295. <span class="sig-name descname"><span class="pre">common_files</span></span><a class="headerlink" href="#filecmp.dircmp.common_files" title="Link to this definition">¶</a></dt>
  296. <dd><p>Files in both <em>a</em> and <em>b</em>.</p>
  297. </dd></dl>
  298. <dl class="py attribute">
  299. <dt class="sig sig-object py" id="filecmp.dircmp.common_funny">
  300. <span class="sig-name descname"><span class="pre">common_funny</span></span><a class="headerlink" href="#filecmp.dircmp.common_funny" title="Link to this definition">¶</a></dt>
  301. <dd><p>Names in both <em>a</em> and <em>b</em>, such that the type differs between the
  302. directories, or names for which <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> reports an error.</p>
  303. </dd></dl>
  304. <dl class="py attribute">
  305. <dt class="sig sig-object py" id="filecmp.dircmp.same_files">
  306. <span class="sig-name descname"><span class="pre">same_files</span></span><a class="headerlink" href="#filecmp.dircmp.same_files" title="Link to this definition">¶</a></dt>
  307. <dd><p>Files which are identical in both <em>a</em> and <em>b</em>, using the class’s
  308. file comparison operator.</p>
  309. </dd></dl>
  310. <dl class="py attribute">
  311. <dt class="sig sig-object py" id="filecmp.dircmp.diff_files">
  312. <span class="sig-name descname"><span class="pre">diff_files</span></span><a class="headerlink" href="#filecmp.dircmp.diff_files" title="Link to this definition">¶</a></dt>
  313. <dd><p>Files which are in both <em>a</em> and <em>b</em>, whose contents differ according
  314. to the class’s file comparison operator.</p>
  315. </dd></dl>
  316. <dl class="py attribute">
  317. <dt class="sig sig-object py" id="filecmp.dircmp.funny_files">
  318. <span class="sig-name descname"><span class="pre">funny_files</span></span><a class="headerlink" href="#filecmp.dircmp.funny_files" title="Link to this definition">¶</a></dt>
  319. <dd><p>Files which are in both <em>a</em> and <em>b</em>, but could not be compared.</p>
  320. </dd></dl>
  321. <dl class="py attribute">
  322. <dt class="sig sig-object py" id="filecmp.dircmp.subdirs">
  323. <span class="sig-name descname"><span class="pre">subdirs</span></span><a class="headerlink" href="#filecmp.dircmp.subdirs" title="Link to this definition">¶</a></dt>
  324. <dd><p>A dictionary mapping names in <a class="reference internal" href="#filecmp.dircmp.common_dirs" title="filecmp.dircmp.common_dirs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">common_dirs</span></code></a> to <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a>
  325. instances (or MyDirCmp instances if this instance is of type MyDirCmp, a
  326. subclass of <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a>).</p>
  327. <div class="versionchanged">
  328. <p><span class="versionmodified changed">Changed in version 3.10: </span>Previously entries were always <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a> instances. Now entries
  329. are the same type as <em>self</em>, if <em>self</em> is a subclass of
  330. <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a>.</p>
  331. </div>
  332. </dd></dl>
  333. </dd></dl>
  334. <dl class="py attribute">
  335. <dt class="sig sig-object py" id="filecmp.DEFAULT_IGNORES">
  336. <span class="sig-prename descclassname"><span class="pre">filecmp.</span></span><span class="sig-name descname"><span class="pre">DEFAULT_IGNORES</span></span><a class="headerlink" href="#filecmp.DEFAULT_IGNORES" title="Link to this definition">¶</a></dt>
  337. <dd><div class="versionadded">
  338. <p><span class="versionmodified added">New in version 3.4.</span></p>
  339. </div>
  340. <p>List of directories ignored by <a class="reference internal" href="#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code></a> by default.</p>
  341. </dd></dl>
  342. <p>Here is a simplified example of using the <code class="docutils literal notranslate"><span class="pre">subdirs</span></code> attribute to search
  343. recursively through two directories to show common different files:</p>
  344. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">filecmp</span> <span class="kn">import</span> <span class="n">dircmp</span>
  345. <span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">print_diff_files</span><span class="p">(</span><span class="n">dcmp</span><span class="p">):</span>
  346. <span class="gp">... </span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dcmp</span><span class="o">.</span><span class="n">diff_files</span><span class="p">:</span>
  347. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;diff_file </span><span class="si">%s</span><span class="s2"> found in </span><span class="si">%s</span><span class="s2"> and </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">dcmp</span><span class="o">.</span><span class="n">left</span><span class="p">,</span>
  348. <span class="gp">... </span> <span class="n">dcmp</span><span class="o">.</span><span class="n">right</span><span class="p">))</span>
  349. <span class="gp">... </span> <span class="k">for</span> <span class="n">sub_dcmp</span> <span class="ow">in</span> <span class="n">dcmp</span><span class="o">.</span><span class="n">subdirs</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
  350. <span class="gp">... </span> <span class="n">print_diff_files</span><span class="p">(</span><span class="n">sub_dcmp</span><span class="p">)</span>
  351. <span class="gp">...</span>
  352. <span class="gp">&gt;&gt;&gt; </span><span class="n">dcmp</span> <span class="o">=</span> <span class="n">dircmp</span><span class="p">(</span><span class="s1">&#39;dir1&#39;</span><span class="p">,</span> <span class="s1">&#39;dir2&#39;</span><span class="p">)</span>
  353. <span class="gp">&gt;&gt;&gt; </span><span class="n">print_diff_files</span><span class="p">(</span><span class="n">dcmp</span><span class="p">)</span>
  354. </pre></div>
  355. </div>
  356. </section>
  357. </section>
  358. <div class="clearer"></div>
  359. </div>
  360. </div>
  361. </div>
  362. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  363. <div class="sphinxsidebarwrapper">
  364. <div>
  365. <h3><a href="../contents.html">Table of Contents</a></h3>
  366. <ul>
  367. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> — File and Directory Comparisons</a><ul>
  368. <li><a class="reference internal" href="#the-dircmp-class">The <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code> class</a></li>
  369. </ul>
  370. </li>
  371. </ul>
  372. </div>
  373. <div>
  374. <h4>Previous topic</h4>
  375. <p class="topless"><a href="stat.html"
  376. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code> — Interpreting <code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code> results</a></p>
  377. </div>
  378. <div>
  379. <h4>Next topic</h4>
  380. <p class="topless"><a href="tempfile.html"
  381. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tempfile</span></code> — Generate temporary files and directories</a></p>
  382. </div>
  383. <div role="note" aria-label="source link">
  384. <h3>This Page</h3>
  385. <ul class="this-page-menu">
  386. <li><a href="../bugs.html">Report a Bug</a></li>
  387. <li>
  388. <a href="https://github.com/python/cpython/blob/main/Doc/library/filecmp.rst"
  389. rel="nofollow">Show Source
  390. </a>
  391. </li>
  392. </ul>
  393. </div>
  394. </div>
  395. <div id="sidebarbutton" title="Collapse sidebar">
  396. <span>«</span>
  397. </div>
  398. </div>
  399. <div class="clearer"></div>
  400. </div>
  401. <div class="related" role="navigation" aria-label="related navigation">
  402. <h3>Navigation</h3>
  403. <ul>
  404. <li class="right" style="margin-right: 10px">
  405. <a href="../genindex.html" title="General Index"
  406. >index</a></li>
  407. <li class="right" >
  408. <a href="../py-modindex.html" title="Python Module Index"
  409. >modules</a> |</li>
  410. <li class="right" >
  411. <a href="tempfile.html" title="tempfile — Generate temporary files and directories"
  412. >next</a> |</li>
  413. <li class="right" >
  414. <a href="stat.html" title="stat — Interpreting stat() results"
  415. >previous</a> |</li>
  416. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  417. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  418. <li class="switchers">
  419. <div class="language_switcher_placeholder"></div>
  420. <div class="version_switcher_placeholder"></div>
  421. </li>
  422. <li>
  423. </li>
  424. <li id="cpython-language-and-version">
  425. <a href="../index.html">3.12.3 Documentation</a> &#187;
  426. </li>
  427. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  428. <li class="nav-item nav-item-2"><a href="filesys.html" >File and Directory Access</a> &#187;</li>
  429. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> — File and Directory Comparisons</a></li>
  430. <li class="right">
  431. <div class="inline-search" role="search">
  432. <form class="inline-search" action="../search.html" method="get">
  433. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  434. <input type="submit" value="Go" />
  435. </form>
  436. </div>
  437. |
  438. </li>
  439. <li class="right">
  440. <label class="theme-selector-label">
  441. Theme
  442. <select class="theme-selector" oninput="activateTheme(this.value)">
  443. <option value="auto" selected>Auto</option>
  444. <option value="light">Light</option>
  445. <option value="dark">Dark</option>
  446. </select>
  447. </label> |</li>
  448. </ul>
  449. </div>
  450. <div class="footer">
  451. &copy;
  452. <a href="../copyright.html">
  453. Copyright
  454. </a>
  455. 2001-2024, Python Software Foundation.
  456. <br />
  457. This page is licensed under the Python Software Foundation License Version 2.
  458. <br />
  459. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  460. <br />
  461. See <a href="/license.html">History and License</a> for more information.<br />
  462. <br />
  463. The Python Software Foundation is a non-profit corporation.
  464. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  465. <br />
  466. <br />
  467. Last updated on Apr 09, 2024 (13:47 UTC).
  468. <a href="/bugs.html">Found a bug</a>?
  469. <br />
  470. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  471. </div>
  472. </body>
  473. </html>
上海开阖软件有限公司 沪ICP备12045867号-1