Iterating Local Directory Contents
Another common operation on a local file
system object is iterating through the contents
of a directory. LocalFS represents local directories
with a LocalDirectory object, which provides
methods for doing just that. These methods are called
fileIds, fileValues, and fileItems.
They work similarly to the objectIds,
objectValues, and objectItems methods
of a Folder object. The difference is that fileValues
and fileItems return LocalFile objects which are
simply pointers to the file objects rather than
the actual Zope objects.
Examples
Using the same LocalFS object from the previous
example, to print the names of all the files
in that directory this is the correct DTML.
<dtml-in "test.fileIds()">
<dtml-var sequence-item><br>
</dtml-in>
Suppose you wanted to print the names of all the files
in a subdirectory called 'sub1'. Here's how you would do
that.
<dtml-in "test['sub1'].fileIds()">
<dtml-var sequence-item><br>
</dtml-in>
The LocalFile object also provides various
meta-information about the local file, so for example,
to add the last modified time of the files to the
output, you would use DTML like the following.
<dtml-in "test.fileValues()">
<dtml-var id> <dtml-var mtime><br>
</dtml-in>
Refer to the product documentation for more information
about LocalFS objects and their attributes.