2
:mod:`dircache` --- Cached directory listings
3
=============================================
6
:synopsis: Return directory listing, with cache mechanism.
10
The :mod:`dircache` module has been removed in Python 3.0.
13
.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
16
The :mod:`dircache` module defines a function for reading directory listing
17
using a cache, and cache invalidation using the *mtime* of the directory.
18
Additionally, it defines a function to annotate directories by appending a
21
The :mod:`dircache` module defines the following functions:
26
Resets the directory cache.
29
.. function:: listdir(path)
31
Return a directory listing of *path*, as gotten from :func:`os.listdir`. Note
32
that unless *path* changes, further call to :func:`listdir` will not re-read the
35
Note that the list returned should be regarded as read-only. (Perhaps a future
36
version should change it to return a tuple?)
39
.. function:: opendir(path)
41
Same as :func:`listdir`. Defined for backwards compatibility.
44
.. function:: annotate(head, list)
46
Assume *list* is a list of paths relative to *head*, and append, in place, a
47
``'/'`` to each path which points to a directory.
52
>>> a = dircache.listdir('/')
53
>>> a = a[:] # Copy the return value so we can change 'a'
55
['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+
56
found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz']
57
>>> dircache.annotate('/', a)
59
['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/
60
', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm