<!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 v2.6.6 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.6.6',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python v2.6.6 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 v2.6.6 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" />
</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="../modindex.html" title="Global Module Index"
accesskey="M">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="../index.html">Python v2.6.6 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">
<h1>10.11. <tt class="xref docutils literal"><span class="pre">dircache</span></tt> — 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 <tt class="xref docutils literal"><span class="pre">dircache</span></tt> module has been removed in Python 3.0.</p>
<p>The <tt class="xref docutils literal"><span class="pre">dircache</span></tt> 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 <tt class="xref docutils literal"><span class="pre">dircache</span></tt> 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>Resets the directory cache.</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 title="os.listdir" class="reference external" href="os.html#os.listdir"><tt class="xref docutils literal"><span class="pre">os.listdir()</span></tt></a>. Note
that unless <em>path</em> changes, further call to <a title="dircache.listdir" class="reference internal" href="#dircache.listdir"><tt class="xref 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>Same as <a title="dircache.listdir" class="reference internal" href="#dircache.listdir"><tt class="xref docutils literal"><span class="pre">listdir()</span></tt></a>. Defined for backwards compatibility.</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>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.</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" size="18" />
<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="../modindex.html" title="Global 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="../index.html">Python v2.6.6 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-2011, 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 20, 2011.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.6.
</div>
</body>
</html>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez