Name
CountDirectoryEntries -- count entries in directory (V8.0)
Synopsis
n, ... = CountDirectoryEntries(id[, what, recursive])
Function
This function can be used to count all entries in the directory specified by id. This directory must have been opened using OpenDirectory() or @DIRECTORY before.

The optional argument what can be used to specify what kind of entries should be counted. The following entry types are currently supported:

#COUNTFILES:
Count all files in the directory. This is the default.

#COUNTDIRECTORIES:
Count all directories in the directory.

#COUNTBOTH:
Count both, files and directories.

#COUNTSEPARATE:
In that mode, files and directories will be counted separately. This means that two values will be returned: The first return value contains the number of files counted, the second return value the number of directories counted. (V9.0)

Starting with Hollywood 9.0, there is a new optional argument named recursive. If this is set to True, CountDirectoryEntries() will recurse into all subdirectories and include those in the count as well.

Note that CountDirectoryEntries() will iterate through all entries in the directory so it must not be used during an iteration using NextDirectoryEntry(). Doing so will automatically rewind any existing directory iterations.

Inputs
id
identifier of the directory whose entries should be counted
what
optional: what should be counted (see above) (defaults to #COUNTFILES)
recursive
optional: whether or not counting should recurse into subdirectories as well (defaults to False) (V9.0)
Results
n
number of entries of desired type in directory
...
optional: additional return values depending on the current count mode (see above)
Example
OpenDirectory(1, "data")
NPrint(CountDirectoryEntries(1))
The code above prints the number of files in the directory data.

Show TOC