parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="filecmp — File and Directory Comparisons" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/filecmp.html" />10<meta property="og:site_name" content="Python documentation" />11<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..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_filecmp_5971fa2a.png" />15<meta property="og:image:alt" 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..." />16<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..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>filecmp — File and Directory Comparisons — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="tempfile — Generate temporary files and directories" href="tempfile.html" />43 <link rel="prev" title="stat — Interpreting stat() results" href="stat.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/filecmp.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <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>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h3><a href="../contents.html">Table of Contents</a></h3>106 <ul>107<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>108<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>109</ul>110</li>111</ul>112 113 </div>114 <div>115 <h4>Previous topic</h4>116 <p class="topless"><a href="stat.html"117 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>118 </div>119 <div>120 <h4>Next topic</h4>121 <p class="topless"><a href="tempfile.html"122 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>123 </div>124 <script>125 document.addEventListener('DOMContentLoaded', () => {126 const title = document.querySelector('meta[property="og:title"]').content;127 const elements = document.querySelectorAll('.improvepage');128 const pageurl = window.location.href.split('?')[0];129 elements.forEach(element => {130 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));131 url.searchParams.set('pagetitle', title);132 url.searchParams.set('pageurl', pageurl);133 url.searchParams.set('pagesource', "library/filecmp.rst");134 element.href = url.toString();135 });136 });137 </script>138 <div role="note" aria-label="source link">139 <h3>This page</h3>140 <ul class="this-page-menu">141 <li><a href="../bugs.html">Report a bug</a></li>142 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>143 <li>144 <a href="https://github.com/python/cpython/blob/main/Doc/library/filecmp.rst?plain=1"145 rel="nofollow">Show source146 </a>147 </li>148 149 </ul>150 </div>151 </nav>152 </div>153</div>154 155 156 <div class="related" role="navigation" aria-label="Related">157 <h3>Navigation</h3>158 <ul>159 <li class="right" style="margin-right: 10px">160 <a href="../genindex.html" title="General Index"161 accesskey="I">index</a></li>162 <li class="right" >163 <a href="../py-modindex.html" title="Python Module Index"164 >modules</a> |</li>165 <li class="right" >166 <a href="tempfile.html" title="tempfile — Generate temporary files and directories"167 accesskey="N">next</a> |</li>168 <li class="right" >169 <a href="stat.html" title="stat — Interpreting stat() results"170 accesskey="P">previous</a> |</li>171 172 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>173 <li><a href="https://www.python.org/">Python</a> »</li>174 <li class="switchers">175 <div class="language_switcher_placeholder"></div>176 <div class="version_switcher_placeholder"></div>177 </li>178 <li>179 180 </li>181 <li id="cpython-language-and-version">182 <a href="../index.html">3.15.0a6 Documentation</a> »183 </li>184 185 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>186 <li class="nav-item nav-item-2"><a href="filesys.html" accesskey="U">File and Directory Access</a> »</li>187 <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>188 <li class="right">189 190 191 <div class="inline-search" role="search">192 <form class="inline-search" action="../search.html" method="get">193 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">194 <input type="submit" value="Go">195 </form>196 </div>197 |198 </li>199 <li class="right">200<label class="theme-selector-label">201 Theme202 <select class="theme-selector" oninput="activateTheme(this.value)">203 <option value="auto" selected>Auto</option>204 <option value="light">Light</option>205 <option value="dark">Dark</option>206 </select>207</label> |</li>208 209 </ul>210 </div> 211 212 <div class="document">213 <div class="documentwrapper">214 <div class="bodywrapper">215 <div class="body" role="main">216 217 <section id="module-filecmp">218<span id="filecmp-file-and-directory-comparisons"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> — File and Directory Comparisons<a class="headerlink" href="#module-filecmp" title="Link to this heading">¶</a></h1>219<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/filecmp.py">Lib/filecmp.py</a></p>220<hr class="docutils" />221<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> module defines functions to compare files and directories,222with various optional time/correctness trade-offs. For comparing files,223see 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>224<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> module defines the following functions:</p>225<dl class="py function">226<dt class="sig sig-object py" id="filecmp.cmp">227<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>228<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,229<code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p>230<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, and231modification time) of both files are identical, the files are taken to be232equal.</p>233<p>Otherwise, the files are treated as different if their sizes or contents differ.</p>234<p>Note that no external programs are called from this function, giving it235portability and efficiency.</p>236<p>This function uses a cache for past comparisons and the results,237with 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 the238file 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>239</dd></dl>240 241<dl class="py function">242<dt class="sig sig-object py" id="filecmp.cmpfiles">243<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>244<dd><p>Compare the files in the two directories <em>dir1</em> and <em>dir2</em> whose names are245given by <em>common</em>.</p>246<p>Returns three lists of file names: <em>match</em>, <em>mismatch</em>,247<em>errors</em>. <em>match</em> contains the list of files that match, <em>mismatch</em> contains248the names of those that don’t, and <em>errors</em> lists the names of files which249could not be compared. Files are listed in <em>errors</em> if they don’t exist in250one of the directories, the user lacks permission to read them or if the251comparison could not be done for some other reason.</p>252<p>The <em>shallow</em> parameter has the same meaning and default value as for253<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>254<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> with255<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 in256one of the three returned lists.</p>257</dd></dl>258 259<dl class="py function">260<dt class="sig sig-object py" id="filecmp.clear_cache">261<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>262<dd><p>Clear the filecmp cache. This may be useful if a file is compared so quickly263after it is modified that it is within the mtime resolution of264the underlying filesystem.</p>265<div class="versionadded">266<p><span class="versionmodified added">Added in version 3.4.</span></p>267</div>268</dd></dl>269 270<section id="the-dircmp-class">271<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>272<dl class="py class">273<dt class="sig sig-object py" id="filecmp.dircmp">274<em class="property"><span class="k"><span class="pre">class</span></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>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></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.dircmp" title="Link to this definition">¶</a></dt>275<dd><p>Construct a new directory comparison object, to compare the directories <em>a</em>276and <em>b</em>. <em>ignore</em> is a list of names to ignore, and defaults to277<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, and278defaults to <code class="docutils literal notranslate"><span class="pre">[os.curdir,</span> <span class="pre">os.pardir]</span></code>.</p>279<p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code> class compares files by doing <em>shallow</em> comparisons280as 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> by default using the <em>shallow</em>281parameter.</p>282<div class="versionchanged">283<p><span class="versionmodified changed">Changed in version 3.13: </span>Added the <em>shallow</em> parameter.</p>284</div>285<p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code> class provides the following methods:</p>286<dl class="py method">287<dt class="sig sig-object py" id="filecmp.dircmp.report">288<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>289<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>290</dd></dl>291 292<dl class="py method">293<dt class="sig sig-object py" id="filecmp.dircmp.report_partial_closure">294<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>295<dd><p>Print a comparison between <em>a</em> and <em>b</em> and common immediate296subdirectories.</p>297</dd></dl>298 299<dl class="py method">300<dt class="sig sig-object py" id="filecmp.dircmp.report_full_closure">301<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>302<dd><p>Print a comparison between <em>a</em> and <em>b</em> and common subdirectories303(recursively).</p>304</dd></dl>305 306<p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code> class offers a number of interesting attributes that may be307used to get various bits of information about the directory trees being308compared.</p>309<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,310so there is no speed penalty if only those attributes which are lightweight311to compute are used.</p>312<dl class="py attribute">313<dt class="sig sig-object py" id="filecmp.dircmp.left">314<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>315<dd><p>The directory <em>a</em>.</p>316</dd></dl>317 318<dl class="py attribute">319<dt class="sig sig-object py" id="filecmp.dircmp.right">320<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>321<dd><p>The directory <em>b</em>.</p>322</dd></dl>323 324<dl class="py attribute">325<dt class="sig sig-object py" id="filecmp.dircmp.left_list">326<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>327<dd><p>Files and subdirectories in <em>a</em>, filtered by <em>hide</em> and <em>ignore</em>.</p>328</dd></dl>329 330<dl class="py attribute">331<dt class="sig sig-object py" id="filecmp.dircmp.right_list">332<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>333<dd><p>Files and subdirectories in <em>b</em>, filtered by <em>hide</em> and <em>ignore</em>.</p>334</dd></dl>335 336<dl class="py attribute">337<dt class="sig sig-object py" id="filecmp.dircmp.common">338<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>339<dd><p>Files and subdirectories in both <em>a</em> and <em>b</em>.</p>340</dd></dl>341 342<dl class="py attribute">343<dt class="sig sig-object py" id="filecmp.dircmp.left_only">344<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>345<dd><p>Files and subdirectories only in <em>a</em>.</p>346</dd></dl>347 348<dl class="py attribute">349<dt class="sig sig-object py" id="filecmp.dircmp.right_only">350<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>351<dd><p>Files and subdirectories only in <em>b</em>.</p>352</dd></dl>353 354<dl class="py attribute">355<dt class="sig sig-object py" id="filecmp.dircmp.common_dirs">356<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>357<dd><p>Subdirectories in both <em>a</em> and <em>b</em>.</p>358</dd></dl>359 360<dl class="py attribute">361<dt class="sig sig-object py" id="filecmp.dircmp.common_files">362<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>363<dd><p>Files in both <em>a</em> and <em>b</em>.</p>364</dd></dl>365 366<dl class="py attribute">367<dt class="sig sig-object py" id="filecmp.dircmp.common_funny">368<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>369<dd><p>Names in both <em>a</em> and <em>b</em>, such that the type differs between the370directories, 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>371</dd></dl>372 373<dl class="py attribute">374<dt class="sig sig-object py" id="filecmp.dircmp.same_files">375<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>376<dd><p>Files which are identical in both <em>a</em> and <em>b</em>, using the class’s377file comparison operator.</p>378</dd></dl>379 380<dl class="py attribute">381<dt class="sig sig-object py" id="filecmp.dircmp.diff_files">382<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>383<dd><p>Files which are in both <em>a</em> and <em>b</em>, whose contents differ according384to the class’s file comparison operator.</p>385</dd></dl>386 387<dl class="py attribute">388<dt class="sig sig-object py" id="filecmp.dircmp.funny_files">389<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>390<dd><p>Files which are in both <em>a</em> and <em>b</em>, but could not be compared.</p>391</dd></dl>392 393<dl class="py attribute">394<dt class="sig sig-object py" id="filecmp.dircmp.subdirs">395<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>396<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 <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code>397instances (or MyDirCmp instances if this instance is of type MyDirCmp, a398subclass of <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code>).</p>399<div class="versionchanged">400<p><span class="versionmodified changed">Changed in version 3.10: </span>Previously entries were always <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code> instances. Now entries401are the same type as <em>self</em>, if <em>self</em> is a subclass of402<code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code>.</p>403</div>404</dd></dl>405 406</dd></dl>407 408<dl class="py data">409<dt class="sig sig-object py" id="filecmp.DEFAULT_IGNORES">410<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>411<dd><div class="versionadded">412<p><span class="versionmodified added">Added in version 3.4.</span></p>413</div>414<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>415</dd></dl>416 417<p>Here is a simplified example of using the <code class="docutils literal notranslate"><span class="pre">subdirs</span></code> attribute to search418recursively through two directories to show common different files:</p>419<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span><span class="w"> </span><span class="nn">filecmp</span><span class="w"> </span><span class="kn">import</span> <span class="n">dircmp</span>420<span class="gp">>>> </span><span class="k">def</span><span class="w"> </span><span class="nf">print_diff_files</span><span class="p">(</span><span class="n">dcmp</span><span class="p">):</span>421<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>422<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"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">"</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>423<span class="gp">... </span> <span class="n">dcmp</span><span class="o">.</span><span class="n">right</span><span class="p">))</span>424<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>425<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>426<span class="gp">...</span>427<span class="gp">>>> </span><span class="n">dcmp</span> <span class="o">=</span> <span class="n">dircmp</span><span class="p">(</span><span class="s1">'dir1'</span><span class="p">,</span> <span class="s1">'dir2'</span><span class="p">)</span>428<span class="gp">>>> </span><span class="n">print_diff_files</span><span class="p">(</span><span class="n">dcmp</span><span class="p">)</span>429</pre></div>430</div>431</section>432</section>433 434 435 <div class="clearer"></div>436 </div>437 </div>438 </div>439 <div class="sphinxsidebar" role="navigation" aria-label="Main">440 <div class="sphinxsidebarwrapper">441 <div>442 <h3><a href="../contents.html">Table of Contents</a></h3>443 <ul>444<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>445<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>446</ul>447</li>448</ul>449 450 </div>451 <div>452 <h4>Previous topic</h4>453 <p class="topless"><a href="stat.html"454 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>455 </div>456 <div>457 <h4>Next topic</h4>458 <p class="topless"><a href="tempfile.html"459 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>460 </div>461 <script>462 document.addEventListener('DOMContentLoaded', () => {463 const title = document.querySelector('meta[property="og:title"]').content;464 const elements = document.querySelectorAll('.improvepage');465 const pageurl = window.location.href.split('?')[0];466 elements.forEach(element => {467 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));468 url.searchParams.set('pagetitle', title);469 url.searchParams.set('pageurl', pageurl);470 url.searchParams.set('pagesource', "library/filecmp.rst");471 element.href = url.toString();472 });473 });474 </script>475 <div role="note" aria-label="source link">476 <h3>This page</h3>477 <ul class="this-page-menu">478 <li><a href="../bugs.html">Report a bug</a></li>479 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>480 <li>481 <a href="https://github.com/python/cpython/blob/main/Doc/library/filecmp.rst?plain=1"482 rel="nofollow">Show source483 </a>484 </li>485 486 </ul>487 </div>488 </div>489<div id="sidebarbutton" title="Collapse sidebar">490<span>«</span>491</div>492 493 </div>494 <div class="clearer"></div>495 </div> 496 <div class="related" role="navigation" aria-label="Related">497 <h3>Navigation</h3>498 <ul>499 <li class="right" style="margin-right: 10px">500 <a href="../genindex.html" title="General Index"501 >index</a></li>502 <li class="right" >503 <a href="../py-modindex.html" title="Python Module Index"504 >modules</a> |</li>505 <li class="right" >506 <a href="tempfile.html" title="tempfile — Generate temporary files and directories"507 >next</a> |</li>508 <li class="right" >509 <a href="stat.html" title="stat — Interpreting stat() results"510 >previous</a> |</li>511 512 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>513 <li><a href="https://www.python.org/">Python</a> »</li>514 <li class="switchers">515 <div class="language_switcher_placeholder"></div>516 <div class="version_switcher_placeholder"></div>517 </li>518 <li>519 520 </li>521 <li id="cpython-language-and-version">522 <a href="../index.html">3.15.0a6 Documentation</a> »523 </li>524 525 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>526 <li class="nav-item nav-item-2"><a href="filesys.html" >File and Directory Access</a> »</li>527 <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>528 <li class="right">529 530 531 <div class="inline-search" role="search">532 <form class="inline-search" action="../search.html" method="get">533 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">534 <input type="submit" value="Go">535 </form>536 </div>537 |538 </li>539 <li class="right">540<label class="theme-selector-label">541 Theme542 <select class="theme-selector" oninput="activateTheme(this.value)">543 <option value="auto" selected>Auto</option>544 <option value="light">Light</option>545 <option value="dark">Dark</option>546 </select>547</label> |</li>548 549 </ul>550 </div> 551 <div class="footer">552 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.553 <br>554 This page is licensed under the Python Software Foundation License Version 2.555 <br>556 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.557 <br>558 559 See <a href="/license.html">History and License</a> for more information.<br>560 561 562 <br>563 564 The Python Software Foundation is a non-profit corporation.565<a href="https://www.python.org/psf/donations/">Please donate.</a>566<br>567 <br>568 Last updated on Mar 10, 2026 (08:58 UTC).569 570 <a href="/bugs.html">Found a bug</a>?571 572 <br>573 574 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.575 </div>576 577 </body>578</html>