source: vendor/python/2.5/Doc/lib/libdircache.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 1.7 KB
Line 
1\section{\module{dircache} ---
2 Cached directory listings}
3
4\declaremodule{standard}{dircache}
5\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
6\modulesynopsis{Return directory listing, with cache mechanism.}
7
8The \module{dircache} module defines a function for reading directory listing
9using a cache, and cache invalidation using the \var{mtime} of the directory.
10Additionally, it defines a function to annotate directories by appending
11a slash.
12
13The \module{dircache} module defines the following functions:
14
15\begin{funcdesc}{reset}{}
16Resets the directory cache.
17\end{funcdesc}
18
19\begin{funcdesc}{listdir}{path}
20Return a directory listing of \var{path}, as gotten from
21\function{os.listdir()}. Note that unless \var{path} changes, further call
22to \function{listdir()} will not re-read the directory structure.
23
24Note that the list returned should be regarded as read-only. (Perhaps
25a future version should change it to return a tuple?)
26\end{funcdesc}
27
28\begin{funcdesc}{opendir}{path}
29Same as \function{listdir()}. Defined for backwards compatibility.
30\end{funcdesc}
31
32\begin{funcdesc}{annotate}{head, list}
33Assume \var{list} is a list of paths relative to \var{head}, and append,
34in place, a \character{/} to each path which points to a directory.
35\end{funcdesc}
36
37\begin{verbatim}
38>>> import dircache
39>>> a = dircache.listdir('/')
40>>> a = a[:] # Copy the return value so we can change 'a'
41>>> a
42['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+
43found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz']
44>>> dircache.annotate('/', a)
45>>> a
46['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/
47', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm
48linuz']
49\end{verbatim}
Note: See TracBrowser for help on using the repository browser.