OpenDirectory -- open a directory for examination (V4.0)
[id] = OpenDirectory(id, dir$[, table])
This function opens the directory specified in dir$ and assigns the specified id to it. If you pass Nil in id, OpenDirectory() will automatically choose a vacant identifier and return it. The directory can then subsequently be examined by using the NextDirectoryEntry() function which gives you low-level access to the directory which is especially useful for large directories or if you need additional information like sizes/attributes for the individual directory entries. You can get these very fast using a loop as presented in the example below.

Starting with Hollywood 6.0 this function accepts an optional table argument which can be used to pass additional parameters. The following table elements are currently recognized:

This tag allows you to specify one or more directory adapters that should be asked to open the specified directory. This must be set to a string containing the name(s) of one or more adapter(s). Defaults to default. See Loaders and adapters for details. (V6.0)

You should call CloseDirectory() as soon as you are finished with the directory. This ensures that the directory does not stay locked by the file system longer than needed.

This command is also available from the preprocessor: Use @DIRECTORY to link whole directories to your applet or executable.

id for the directory or Nil for auto id selection
name of the directory to open
optional: table containing further parameters (V6.0)
optional: identifier of the directory; will only be returned when you pass Nil as argument 1 (see above)
OpenDirectory(1, "Data")
e = NextDirectoryEntry(1)
While e <> Nil
  NPrint(IIf(e.type = #DOSTYPE_FILE, "File:", "Directory:"),
  e = NextDirectoryEntry(1)
The code above opens directory "Data" and prints all files and directories present in that directory.

Show TOC