blob: 45ac01a2478207e2af75cf4c191d55bae3060041 [file] [log] [blame]
Fred Drake64bc94e1999-06-17 15:11:35 +00001\section{\module{dircache} ---
2 Cached directory listings}
3
4\declaremodule{standard}{dircache}
5\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
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}{listdir}{path}
16Return a directory listing of \var{path}, as gotten from
17\function{os.listdir()}. Note that unless \var{path} changes, further call
18to \function{listdir()} will not re-read the directory structure.
19
20Note that the list returned should be regarded as read-only. (Perhaps
21a future version should change it to return a tuple?)
22\end{funcdesc}
23
24\begin{funcdesc}{opendir}{path}
Thomas Woutersf8316632000-07-16 19:01:10 +000025Same as \function{listdir()}. Defined for backwards compatibility.
Fred Drake64bc94e1999-06-17 15:11:35 +000026\end{funcdesc}
27
28\begin{funcdesc}{annotate}{head, list}
Fred Drake6cf186b1999-10-29 17:51:29 +000029Assume \var{list} is a list of paths relative to \var{head}, and append,
Fred Drake64bc94e1999-06-17 15:11:35 +000030in place, a \character{/} to each path which points to a directory.
31\end{funcdesc}
32
33\begin{verbatim}
34>>> import dircache
35>>> a=dircache.listdir('/')
36>>> a=a[:] # Copy the return value so we can change 'a'
37>>> a
38['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+
39found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz']
40>>> dircache.annotate('/', a)
41>>> a
42['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/
43', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm
44linuz']
45\end{verbatim}