Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
filesys.html426 linesDownload Raw Back to docs
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="File and Directory Access" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/filesys.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="The modules described in this chapter deal with disk files and directories. For example, there are modules for reading the properties of files, manipulating paths in a portable way, and creating te..." />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_filesys_379d330e.png" />15<meta property="og:image:alt" content="The modules described in this chapter deal with disk files and directories. For example, there are modules for reading the properties of files, manipulating paths in a portable way, and creating te..." />16<meta name="description" content="The modules described in this chapter deal with disk files and directories. For example, there are modules for reading the properties of files, manipulating paths in a portable way, and creating te..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>File and Directory Access &#8212; 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="pathlib — Object-oriented filesystem paths" href="pathlib.html" />43    <link rel="prev" title="operator — Standard operators as functions" href="operator.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/filesys.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    <h4>Previous topic</h4>106    <p class="topless"><a href="operator.html"107                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code> — Standard operators as functions</a></p>108  </div>109  <div>110    <h4>Next topic</h4>111    <p class="topless"><a href="pathlib.html"112                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code> — Object-oriented filesystem paths</a></p>113  </div>114  <script>115    document.addEventListener('DOMContentLoaded', () => {116        const title = document.querySelector('meta[property="og:title"]').content;117        const elements = document.querySelectorAll('.improvepage');118        const pageurl = window.location.href.split('?')[0];119        elements.forEach(element => {120            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));121            url.searchParams.set('pagetitle', title);122            url.searchParams.set('pageurl', pageurl);123            url.searchParams.set('pagesource', "library/filesys.rst");124            element.href = url.toString();125        });126    });127  </script>128  <div role="note" aria-label="source link">129    <h3>This page</h3>130    <ul class="this-page-menu">131      <li><a href="../bugs.html">Report a bug</a></li>132      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>133      <li>134        <a href="https://github.com/python/cpython/blob/main/Doc/library/filesys.rst?plain=1"135            rel="nofollow">Show source136        </a>137      </li>138      139    </ul>140  </div>141        </nav>142    </div>143</div>144 145  146    <div class="related" role="navigation" aria-label="Related">147      <h3>Navigation</h3>148      <ul>149        <li class="right" style="margin-right: 10px">150          <a href="../genindex.html" title="General Index"151             accesskey="I">index</a></li>152        <li class="right" >153          <a href="../py-modindex.html" title="Python Module Index"154             >modules</a> |</li>155        <li class="right" >156          <a href="pathlib.html" title="pathlib — Object-oriented filesystem paths"157             accesskey="N">next</a> |</li>158        <li class="right" >159          <a href="operator.html" title="operator — Standard operators as functions"160             accesskey="P">previous</a> |</li>161 162          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>163          <li><a href="https://www.python.org/">Python</a> &#187;</li>164          <li class="switchers">165            <div class="language_switcher_placeholder"></div>166            <div class="version_switcher_placeholder"></div>167          </li>168          <li>169              170          </li>171    <li id="cpython-language-and-version">172      <a href="../index.html">3.15.0a6 Documentation</a> &#187;173    </li>174 175          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">The Python Standard Library</a> &#187;</li>176        <li class="nav-item nav-item-this"><a href="">File and Directory Access</a></li>177                <li class="right">178                    179 180    <div class="inline-search" role="search">181        <form class="inline-search" action="../search.html" method="get">182          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">183          <input type="submit" value="Go">184        </form>185    </div>186                     |187                </li>188            <li class="right">189<label class="theme-selector-label">190    Theme191    <select class="theme-selector" oninput="activateTheme(this.value)">192        <option value="auto" selected>Auto</option>193        <option value="light">Light</option>194        <option value="dark">Dark</option>195    </select>196</label> |</li>197            198      </ul>199    </div>    200 201    <div class="document">202      <div class="documentwrapper">203        <div class="bodywrapper">204          <div class="body" role="main">205            206  <section id="file-and-directory-access">207<span id="filesys"></span><h1>File and Directory Access<a class="headerlink" href="#file-and-directory-access" title="Link to this heading">¶</a></h1>208<p>The modules described in this chapter deal with disk files and directories.  For209example, there are modules for reading the properties of files, manipulating210paths in a portable way, and creating temporary files.  The full list of modules211in this chapter is:</p>212<div class="toctree-wrapper compound">213<ul>214<li class="toctree-l1"><a class="reference internal" href="pathlib.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code> — Object-oriented filesystem paths</a><ul>215<li class="toctree-l2"><a class="reference internal" href="pathlib.html#basic-use">Basic use</a></li>216<li class="toctree-l2"><a class="reference internal" href="pathlib.html#exceptions">Exceptions</a></li>217<li class="toctree-l2"><a class="reference internal" href="pathlib.html#pure-paths">Pure paths</a><ul>218<li class="toctree-l3"><a class="reference internal" href="pathlib.html#general-properties">General properties</a></li>219<li class="toctree-l3"><a class="reference internal" href="pathlib.html#operators">Operators</a></li>220<li class="toctree-l3"><a class="reference internal" href="pathlib.html#accessing-individual-parts">Accessing individual parts</a></li>221<li class="toctree-l3"><a class="reference internal" href="pathlib.html#methods-and-properties">Methods and properties</a></li>222</ul>223</li>224<li class="toctree-l2"><a class="reference internal" href="pathlib.html#concrete-paths">Concrete paths</a><ul>225<li class="toctree-l3"><a class="reference internal" href="pathlib.html#parsing-and-generating-uris">Parsing and generating URIs</a></li>226<li class="toctree-l3"><a class="reference internal" href="pathlib.html#expanding-and-resolving-paths">Expanding and resolving paths</a></li>227<li class="toctree-l3"><a class="reference internal" href="pathlib.html#querying-file-type-and-status">Querying file type and status</a></li>228<li class="toctree-l3"><a class="reference internal" href="pathlib.html#reading-and-writing-files">Reading and writing files</a></li>229<li class="toctree-l3"><a class="reference internal" href="pathlib.html#reading-directories">Reading directories</a></li>230<li class="toctree-l3"><a class="reference internal" href="pathlib.html#creating-files-and-directories">Creating files and directories</a></li>231<li class="toctree-l3"><a class="reference internal" href="pathlib.html#copying-moving-and-deleting">Copying, moving and deleting</a></li>232<li class="toctree-l3"><a class="reference internal" href="pathlib.html#permissions-and-ownership">Permissions and ownership</a></li>233</ul>234</li>235<li class="toctree-l2"><a class="reference internal" href="pathlib.html#pattern-language">Pattern language</a></li>236<li class="toctree-l2"><a class="reference internal" href="pathlib.html#comparison-to-the-glob-module">Comparison to the <code class="xref py py-mod docutils literal notranslate"><span class="pre">glob</span></code> module</a></li>237<li class="toctree-l2"><a class="reference internal" href="pathlib.html#comparison-to-the-os-and-os-path-modules">Comparison to the <code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code> modules</a><ul>238<li class="toctree-l3"><a class="reference internal" href="pathlib.html#corresponding-tools">Corresponding tools</a></li>239</ul>240</li>241<li class="toctree-l2"><a class="reference internal" href="pathlib.html#module-pathlib.types">Protocols</a></li>242</ul>243</li>244<li class="toctree-l1"><a class="reference internal" href="os.path.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code> — Common pathname manipulations</a></li>245<li class="toctree-l1"><a class="reference internal" href="stat.html"><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></li>246<li class="toctree-l1"><a class="reference internal" href="filecmp.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> — File and Directory Comparisons</a><ul>247<li class="toctree-l2"><a class="reference internal" href="filecmp.html#the-dircmp-class">The <code class="xref py py-class docutils literal notranslate"><span class="pre">dircmp</span></code> class</a></li>248</ul>249</li>250<li class="toctree-l1"><a class="reference internal" href="tempfile.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tempfile</span></code> — Generate temporary files and directories</a><ul>251<li class="toctree-l2"><a class="reference internal" href="tempfile.html#examples">Examples</a></li>252<li class="toctree-l2"><a class="reference internal" href="tempfile.html#deprecated-functions-and-variables">Deprecated functions and variables</a></li>253</ul>254</li>255<li class="toctree-l1"><a class="reference internal" href="glob.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">glob</span></code> — Unix style pathname pattern expansion</a><ul>256<li class="toctree-l2"><a class="reference internal" href="glob.html#examples">Examples</a></li>257</ul>258</li>259<li class="toctree-l1"><a class="reference internal" href="fnmatch.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fnmatch</span></code> — Unix filename pattern matching</a></li>260<li class="toctree-l1"><a class="reference internal" href="linecache.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">linecache</span></code> — Random access to text lines</a></li>261<li class="toctree-l1"><a class="reference internal" href="shutil.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">shutil</span></code> — High-level file operations</a><ul>262<li class="toctree-l2"><a class="reference internal" href="shutil.html#directory-and-files-operations">Directory and files operations</a><ul>263<li class="toctree-l3"><a class="reference internal" href="shutil.html#platform-dependent-efficient-copy-operations">Platform-dependent efficient copy operations</a></li>264<li class="toctree-l3"><a class="reference internal" href="shutil.html#copytree-example">copytree example</a></li>265<li class="toctree-l3"><a class="reference internal" href="shutil.html#rmtree-example">rmtree example</a></li>266</ul>267</li>268<li class="toctree-l2"><a class="reference internal" href="shutil.html#archiving-operations">Archiving operations</a><ul>269<li class="toctree-l3"><a class="reference internal" href="shutil.html#archiving-example">Archiving example</a></li>270<li class="toctree-l3"><a class="reference internal" href="shutil.html#archiving-example-with-base-dir">Archiving example with <em>base_dir</em></a></li>271</ul>272</li>273<li class="toctree-l2"><a class="reference internal" href="shutil.html#querying-the-size-of-the-output-terminal">Querying the size of the output terminal</a></li>274</ul>275</li>276</ul>277</div>278<div class="admonition seealso">279<p class="admonition-title">See also</p>280<dl class="simple">281<dt>Module <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a></dt><dd><p>Operating system interfaces, including functions to work with files at a282lower level than Python <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file objects</span></a>.</p>283</dd>284<dt>Module <a class="reference internal" href="io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a></dt><dd><p>Python’s built-in I/O library, including both abstract classes and285some concrete classes such as file I/O.</p>286</dd>287<dt>Built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a></dt><dd><p>The standard way to open files for reading and writing with Python.</p>288</dd>289</dl>290</div>291</section>292 293 294            <div class="clearer"></div>295          </div>296        </div>297      </div>298      <div class="sphinxsidebar" role="navigation" aria-label="Main">299        <div class="sphinxsidebarwrapper">300  <div>301    <h4>Previous topic</h4>302    <p class="topless"><a href="operator.html"303                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code> — Standard operators as functions</a></p>304  </div>305  <div>306    <h4>Next topic</h4>307    <p class="topless"><a href="pathlib.html"308                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code> — Object-oriented filesystem paths</a></p>309  </div>310  <script>311    document.addEventListener('DOMContentLoaded', () => {312        const title = document.querySelector('meta[property="og:title"]').content;313        const elements = document.querySelectorAll('.improvepage');314        const pageurl = window.location.href.split('?')[0];315        elements.forEach(element => {316            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));317            url.searchParams.set('pagetitle', title);318            url.searchParams.set('pageurl', pageurl);319            url.searchParams.set('pagesource', "library/filesys.rst");320            element.href = url.toString();321        });322    });323  </script>324  <div role="note" aria-label="source link">325    <h3>This page</h3>326    <ul class="this-page-menu">327      <li><a href="../bugs.html">Report a bug</a></li>328      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>329      <li>330        <a href="https://github.com/python/cpython/blob/main/Doc/library/filesys.rst?plain=1"331            rel="nofollow">Show source332        </a>333      </li>334      335    </ul>336  </div>337        </div>338<div id="sidebarbutton" title="Collapse sidebar">339<span>«</span>340</div>341 342      </div>343      <div class="clearer"></div>344    </div>  345    <div class="related" role="navigation" aria-label="Related">346      <h3>Navigation</h3>347      <ul>348        <li class="right" style="margin-right: 10px">349          <a href="../genindex.html" title="General Index"350             >index</a></li>351        <li class="right" >352          <a href="../py-modindex.html" title="Python Module Index"353             >modules</a> |</li>354        <li class="right" >355          <a href="pathlib.html" title="pathlib — Object-oriented filesystem paths"356             >next</a> |</li>357        <li class="right" >358          <a href="operator.html" title="operator — Standard operators as functions"359             >previous</a> |</li>360 361          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>362          <li><a href="https://www.python.org/">Python</a> &#187;</li>363          <li class="switchers">364            <div class="language_switcher_placeholder"></div>365            <div class="version_switcher_placeholder"></div>366          </li>367          <li>368              369          </li>370    <li id="cpython-language-and-version">371      <a href="../index.html">3.15.0a6 Documentation</a> &#187;372    </li>373 374          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>375        <li class="nav-item nav-item-this"><a href="">File and Directory Access</a></li>376                <li class="right">377                    378 379    <div class="inline-search" role="search">380        <form class="inline-search" action="../search.html" method="get">381          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">382          <input type="submit" value="Go">383        </form>384    </div>385                     |386                </li>387            <li class="right">388<label class="theme-selector-label">389    Theme390    <select class="theme-selector" oninput="activateTheme(this.value)">391        <option value="auto" selected>Auto</option>392        <option value="light">Light</option>393        <option value="dark">Dark</option>394    </select>395</label> |</li>396            397      </ul>398    </div>  399    <div class="footer">400    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.401    <br>402    This page is licensed under the Python Software Foundation License Version 2.403    <br>404    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.405    <br>406    407      See <a href="/license.html">History and License</a> for more information.<br>408    409    410    <br>411 412    The Python Software Foundation is a non-profit corporation.413<a href="https://www.python.org/psf/donations/">Please donate.</a>414<br>415    <br>416      Last updated on Mar 10, 2026 (08:58 UTC).417    418      <a href="/bugs.html">Found a bug</a>?419    420    <br>421 422    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.423    </div>424 425  </body>426</html>