Manual:DIL Manual/unitdir()
unitdir()
Function (stringlist). Lists the unit files that DIL has stored, by a pattern.
unitdir(pattern : string)
Returns the names of the files in the units directory that match pattern: the files store() writes and restore() and delunit() read. death.zon uses unitdir(".*") at boot to bring back the corpses that were stored before a crash or reboot.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pattern | string | A regular expression that must match the whole file name. "" means all files. |
Returns
Stringlist: the matching file names, in no particular order (the order the directory gives them). Empty when nothing matches or the directory doesn't exist. It fails if pattern fails, is a string variable that has never had a value, or is not a valid regular expression; assigning a failed list leaves the variable as it was.
Notes
- The pattern is a regular expression (Perl style), not a shell wildcard:
".*"is everything,"corpse[.].*"is every name starting with "corpse.", and a plain.matches any character. A shell-style"*"is not a valid expression. - The directory is
units/under the zone's DIL file directory: the sixth column of the zone's line invme/etc/zonelist(death has../lib/death), or elsedil_file_dirinserver.cfg. The zone is that of the program the unit runs; a function from another zone that it calls (f@otherzone) still looks in the calling program's directory. - Only file names are returned, without a path, ready for
restore().
Example
dilbegin aware reload_units();
var
files : stringlist;
u : unitptr;
i : integer;
n : integer;
code
{
files := unitdir("corpse[.].*");
n := length(files);
i := 0;
while (i < n)
{
u := restore(files.[i], null);
if (u == null)
log("reload_units: could not restore " + files.[i]);
i := i + 1;
}
quit;
}
dilend
Brings back every stored unit whose file name starts with "corpse.", into the unit that runs it (restore() with null puts it there); adapted from reload_corpse in death.zon.