Name
OpenDirectory -- open a directory for examination (V4.0)
Synopsis
[id] = OpenDirectory(id, dir$[, table])
Function
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 an 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:

Adapter:
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 the adapter set using SetDefaultAdapter(). See Loaders and adapters for details. (V6.0)

UserTags:
This tag can be used to specify additional data that should be passed to directory adapters. If you use this tag, you must set it to a table of key-value pairs that contain the additional data that should be passed to plugins. See User tags for details. (V10.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.

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

Show TOC