Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-stat.html" /> | |
13 | <link rel="prev" href="module-os.path.html" /> | |
14 | <link rel="parent" href="allos.html" /> | |
15 | <link rel="next" href="module-stat.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.3 dircache -- Cached directory listings</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6.2 os.path " | |
25 | href="module-os.path.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
28 | href="allos.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.4 stat " | |
31 | href="module-stat.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-os.path.html">6.2 os.path </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-stat.html">6.4 stat </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION008300000000000000000"> | |
56 | 6.3 <tt class="module">dircache</tt> -- | |
57 | Cached directory listings</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-dircache"></A> | |
62 | ||
63 | <P> | |
64 | The <tt class="module">dircache</tt> module defines a function for reading directory listing | |
65 | using a cache, and cache invalidation using the <var>mtime</var> of the directory. | |
66 | Additionally, it defines a function to annotate directories by appending | |
67 | a slash. | |
68 | ||
69 | <P> | |
70 | The <tt class="module">dircache</tt> module defines the following functions: | |
71 | ||
72 | <P> | |
73 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
74 | <td><nobr><b><tt id='l2h-1772' xml:id='l2h-1772' class="function">listdir</tt></b>(</nobr></td> | |
75 | <td><var>path</var>)</td></tr></table></dt> | |
76 | <dd> | |
77 | Return a directory listing of <var>path</var>, as gotten from | |
78 | <tt class="function">os.listdir()</tt>. Note that unless <var>path</var> changes, further call | |
79 | to <tt class="function">listdir()</tt> will not re-read the directory structure. | |
80 | ||
81 | <P> | |
82 | Note that the list returned should be regarded as read-only. (Perhaps | |
83 | a future version should change it to return a tuple?) | |
84 | </dl> | |
85 | ||
86 | <P> | |
87 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
88 | <td><nobr><b><tt id='l2h-1773' xml:id='l2h-1773' class="function">opendir</tt></b>(</nobr></td> | |
89 | <td><var>path</var>)</td></tr></table></dt> | |
90 | <dd> | |
91 | Same as <tt class="function">listdir()</tt>. Defined for backwards compatibility. | |
92 | </dl> | |
93 | ||
94 | <P> | |
95 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
96 | <td><nobr><b><tt id='l2h-1774' xml:id='l2h-1774' class="function">annotate</tt></b>(</nobr></td> | |
97 | <td><var>head, list</var>)</td></tr></table></dt> | |
98 | <dd> | |
99 | Assume <var>list</var> is a list of paths relative to <var>head</var>, and append, | |
100 | in place, a "<tt class="character">/</tt>" to each path which points to a directory. | |
101 | </dl> | |
102 | ||
103 | <P> | |
104 | <div class="verbatim"><pre> | |
105 | >>> import dircache | |
106 | >>> a = dircache.listdir('/') | |
107 | >>> a = a[:] # Copy the return value so we can change 'a' | |
108 | >>> a | |
109 | ['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+ | |
110 | found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz'] | |
111 | >>> dircache.annotate('/', a) | |
112 | >>> a | |
113 | ['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/ | |
114 | ', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm | |
115 | linuz'] | |
116 | </pre></div> | |
117 | ||
118 | <DIV CLASS="navigation"> | |
119 | <div class='online-navigation'> | |
120 | <p></p><hr /> | |
121 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
122 | <tr> | |
123 | <td class='online-navigation'><a rel="prev" title="6.2 os.path " | |
124 | href="module-os.path.html"><img src='../icons/previous.png' | |
125 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
126 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
127 | href="allos.html"><img src='../icons/up.png' | |
128 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
129 | <td class='online-navigation'><a rel="next" title="6.4 stat " | |
130 | href="module-stat.html"><img src='../icons/next.png' | |
131 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
132 | <td align="center" width="100%">Python Library Reference</td> | |
133 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
134 | href="contents.html"><img src='../icons/contents.png' | |
135 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
136 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
137 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
138 | <td class='online-navigation'><a rel="index" title="Index" | |
139 | href="genindex.html"><img src='../icons/index.png' | |
140 | border='0' height='32' alt='Index' width='32' /></A></td> | |
141 | </tr></table> | |
142 | <div class='online-navigation'> | |
143 | <b class="navlabel">Previous:</b> | |
144 | <a class="sectref" rel="prev" href="module-os.path.html">6.2 os.path </A> | |
145 | <b class="navlabel">Up:</b> | |
146 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
147 | <b class="navlabel">Next:</b> | |
148 | <a class="sectref" rel="next" href="module-stat.html">6.4 stat </A> | |
149 | </div> | |
150 | </div> | |
151 | <hr /> | |
152 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
153 | </DIV> | |
154 | <!--End of Navigation Panel--> | |
155 | <ADDRESS> | |
156 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
157 | </ADDRESS> | |
158 | </BODY> | |
159 | </HTML> |