korsygfhrtzangaiide
Elepffwdsff
/
usr
/
share
/
doc
/
python-docs-2.7.5
/
html
/
library
/
Upload FileeE
HOME
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>10.11. dircache — Cached directory listings — Python 2.7.5 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.7.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.5 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="top" title="Python 2.7.5 documentation" href="../index.html" /> <link rel="up" title="10. File and Directory Access" href="filesys.html" /> <link rel="next" title="10.12. macpath — Mac OS 9 path manipulation functions" href="macpath.html" /> <link rel="prev" title="10.10. shutil — High-level file operations" href="shutil.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="macpath.html" title="10.12. macpath — Mac OS 9 path manipulation functions" accesskey="N">next</a> |</li> <li class="right" > <a href="shutil.html" title="10.10. shutil — High-level file operations" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="filesys.html" accesskey="U">10. File and Directory Access</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-dircache"> <span id="dircache-cached-directory-listings"></span><h1>10.11. <a class="reference internal" href="#module-dircache" title="dircache: Return directory listing, with cache mechanism. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">dircache</span></tt></a> — Cached directory listings<a class="headerlink" href="#module-dircache" title="Permalink to this headline">¶</a></h1> <p class="deprecated"> <span class="versionmodified">Deprecated since version 2.6: </span>The <a class="reference internal" href="#module-dircache" title="dircache: Return directory listing, with cache mechanism. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">dircache</span></tt></a> module has been removed in Python 3.</p> <p>The <a class="reference internal" href="#module-dircache" title="dircache: Return directory listing, with cache mechanism. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">dircache</span></tt></a> module defines a function for reading directory listing using a cache, and cache invalidation using the <em>mtime</em> of the directory. Additionally, it defines a function to annotate directories by appending a slash.</p> <p>The <a class="reference internal" href="#module-dircache" title="dircache: Return directory listing, with cache mechanism. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">dircache</span></tt></a> module defines the following functions:</p> <dl class="function"> <dt id="dircache.reset"> <tt class="descclassname">dircache.</tt><tt class="descname">reset</tt><big>(</big><big>)</big><a class="headerlink" href="#dircache.reset" title="Permalink to this definition">¶</a></dt> <dd><p>Resets the directory cache.</p> </dd></dl> <dl class="function"> <dt id="dircache.listdir"> <tt class="descclassname">dircache.</tt><tt class="descname">listdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#dircache.listdir" title="Permalink to this definition">¶</a></dt> <dd><p>Return a directory listing of <em>path</em>, as gotten from <a class="reference internal" href="os.html#os.listdir" title="os.listdir"><tt class="xref py py-func docutils literal"><span class="pre">os.listdir()</span></tt></a>. Note that unless <em>path</em> changes, further call to <a class="reference internal" href="#dircache.listdir" title="dircache.listdir"><tt class="xref py py-func docutils literal"><span class="pre">listdir()</span></tt></a> will not re-read the directory structure.</p> <p>Note that the list returned should be regarded as read-only. (Perhaps a future version should change it to return a tuple?)</p> </dd></dl> <dl class="function"> <dt id="dircache.opendir"> <tt class="descclassname">dircache.</tt><tt class="descname">opendir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#dircache.opendir" title="Permalink to this definition">¶</a></dt> <dd><p>Same as <a class="reference internal" href="#dircache.listdir" title="dircache.listdir"><tt class="xref py py-func docutils literal"><span class="pre">listdir()</span></tt></a>. Defined for backwards compatibility.</p> </dd></dl> <dl class="function"> <dt id="dircache.annotate"> <tt class="descclassname">dircache.</tt><tt class="descname">annotate</tt><big>(</big><em>head</em>, <em>list</em><big>)</big><a class="headerlink" href="#dircache.annotate" title="Permalink to this definition">¶</a></dt> <dd><p>Assume <em>list</em> is a list of paths relative to <em>head</em>, and append, in place, a <tt class="docutils literal"><span class="pre">'/'</span></tt> to each path which points to a directory.</p> </dd></dl> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">dircache</span> <span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">dircache</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="s">'/'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">a</span><span class="p">[:]</span> <span class="c"># Copy the return value so we can change 'a'</span> <span class="gp">>>> </span><span class="n">a</span> <span class="go">['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+</span> <span class="go">found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz']</span> <span class="gp">>>> </span><span class="n">dircache</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s">'/'</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">a</span> <span class="go">['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/</span> <span class="go">', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm</span> <span class="go">linuz']</span> </pre></div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="shutil.html" title="previous chapter">10.10. <tt class="docutils literal"><span class="pre">shutil</span></tt> — High-level file operations</a></p> <h4>Next topic</h4> <p class="topless"><a href="macpath.html" title="next chapter">10.12. <tt class="docutils literal"><span class="pre">macpath</span></tt> — Mac OS 9 path manipulation functions</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li><a href="../_sources/library/dircache.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="macpath.html" title="10.12. macpath — Mac OS 9 path manipulation functions" >next</a> |</li> <li class="right" > <a href="shutil.html" title="10.10. shutil — High-level file operations" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="filesys.html" >10. File and Directory Access</a> »</li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="http://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Jul 03, 2019. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>