| Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 1 | \section{\module{dircache} --- | 
 | 2 |          Cached directory listings} | 
 | 3 |  | 
 | 4 | \declaremodule{standard}{dircache} | 
| Fred Drake | 57657bc | 2000-12-01 15:25:23 +0000 | [diff] [blame] | 5 | \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il} | 
| Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 6 | \modulesynopsis{Return directory listing, with cache mechanism.} | 
 | 7 |  | 
 | 8 | The \module{dircache} module defines a function for reading directory listing | 
 | 9 | using a cache, and cache invalidation using the \var{mtime} of the directory. | 
 | 10 | Additionally, it defines a function to annotate directories by appending | 
 | 11 | a slash. | 
 | 12 |  | 
 | 13 | The \module{dircache} module defines the following functions: | 
 | 14 |  | 
| Skip Montanaro | 4f49e7d | 2005-01-05 07:03:53 +0000 | [diff] [blame] | 15 | \begin{funcdesc}{reset}{} | 
 | 16 | Resets the directory cache. | 
 | 17 | \end{funcdesc} | 
 | 18 |  | 
| Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 19 | \begin{funcdesc}{listdir}{path} | 
 | 20 | Return a directory listing of \var{path}, as gotten from | 
 | 21 | \function{os.listdir()}. Note that unless \var{path} changes, further call | 
 | 22 | to \function{listdir()} will not re-read the directory structure. | 
 | 23 |  | 
 | 24 | Note that the list returned should be regarded as read-only. (Perhaps | 
 | 25 | a future version should change it to return a tuple?) | 
 | 26 | \end{funcdesc} | 
 | 27 |  | 
 | 28 | \begin{funcdesc}{opendir}{path} | 
| Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 29 | Same as \function{listdir()}. Defined for backwards compatibility. | 
| Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 30 | \end{funcdesc} | 
 | 31 |  | 
 | 32 | \begin{funcdesc}{annotate}{head, list} | 
| Fred Drake | 6cf186b | 1999-10-29 17:51:29 +0000 | [diff] [blame] | 33 | Assume \var{list} is a list of paths relative to \var{head}, and append, | 
| Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 34 | in place, a \character{/} to each path which points to a directory. | 
 | 35 | \end{funcdesc} | 
 | 36 |  | 
 | 37 | \begin{verbatim} | 
 | 38 | >>> import dircache | 
| Fred Drake | a180581 | 2003-12-31 07:41:52 +0000 | [diff] [blame] | 39 | >>> a = dircache.listdir('/') | 
 | 40 | >>> a = a[:] # Copy the return value so we can change 'a' | 
| Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 41 | >>> a | 
 | 42 | ['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+ | 
 | 43 | found', '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 | 
 | 48 | linuz'] | 
 | 49 | \end{verbatim} |