Name
DIRECTORY -- link whole directory into applet or executable (V8.0)
Synopsis
@DIRECTORY id, dir$[, table]
Function
This preprocessor command can be used to link the whole directory specified in dir$ into your applet or executable when compiling your script. This makes it possible to conveniently link a lot of files into your applet or executable when compiling your script because you only need to add one additional line to your script instead of individual lines for each file.

Note that if you use @DIRECTORY you have to use the GetDirectoryEntry() function to access individual files and subdirectories stored in the directory that you have linked to your applet or executable. See below for an example. In case you are just running your script using the Hollywood interpreter, GetDirectoryEntry() will simply return the string you passed to it so that the script will work identically no matter if you're running it as a script using the Hollywood interpreter or if you've compiled it as an applet or executable. See GetDirectoryEntry for details.

This preprocessor command also accepts an optional table argument that can be used to configure further options. The following tags are currently supported by the optional table argument:

Recursive:
If this tag is set to True, @DIRECTORY will link all files in subdirectories of dir$ as well. This is the default. Set it to False if you don't want @DIRECTORY to recurse into subdirectories as well.

Link:
Set this field to False if you do not want to have this directory linked to your executable/applet when you compile your script. This field defaults to True which means that the directory will be linked to your executable/applet when Hollywood is in compile mode.

Note that @DIRECTORY doesn't only link all files and subdirectories inside dir$ into your applet or executable, it will also create a directory object which can then be used with all functions that support directory objects, e.g. NextDirectoryEntry() and RewindDirectory(). It is even possible to iterate over all files and subdirectories linked by @DIRECTORY to your script. See below for an example.

Finally, please note that only file/directory names, sizes, and the files' actual content will be linked to your applet or executable. File attributes like protection flags, date stamps, and comments won't be linked so if you try to query them, you'll get some default values instead.

If you want to open directories at runtime, please use the OpenDirectory() command.

Inputs
id
a value that is used to identify this directory later in the code
dir$
the directory you want to have linked to your applet or executable
table
optional: a table containing further options (see above)
Example
@DIRECTORY 1, "data"
LoadBrush(1, GetDirectoryEntry("data/title.png"))
The code above shows how to link all files and subdirectories inside the data directory to your applet or executable and then load the file title.png from this directory into brush 1. Note that in case the script hasn't been compiled as an applet or executable, LoadBrush() will simply load the file from data/title.png. In case the script has been compiled as an applet or executable, however, the file title.png is loaded directly from the applet or executable because it has been linked to it.


@DIRECTORY 1, "data"

Function p_DumpDirs(d$, indent)
    Local handle
    If d$ <> ""
        handle = OpenDirectory(Nil, GetDirectoryFile(1, d$))
    Else
        handle = 1
    EndIf
    Local e = NextDirectoryEntry(handle)
    While e <> Nil
        If e.Type = #DOSTYPE_DIRECTORY Then e.size = 0
        NPrint(RepeatStr(" ", indent) .. IIf(e.type = #DOSTYPE_FILE,
            "File:", "Directory:") .. " " .. e.name .. " " .. e.size
            .. " " .. HexStr(e.flags) .. " " .. e.time)
        If e.Type = #DOSTYPE_DIRECTORY Then p_DumpDirs(FullPath(d$,
            e.name), indent + 4)
        e = NextDirectoryEntry(handle)
    Wend
    If GetType(handle) = #LIGHTUSERDATA Then CloseDirectory(handle)
EndFunction

p_DumpDirs("", 0)
The code above shows how to recursively print all files and directories in a directory that has been linked to the applet or executable.

Show TOC