Manual:DIL Manual/strdir()
Jump to navigation
Jump to search
strdir()
Function (stringlist). Lists the string files that DIL has saved, by a pattern.
strdir(pattern : string)
Returns the names of the files in the strings directory that match pattern: the files savestr() writes and loadstr() and delstr() read. Competition.zon, for instance, uses strdir(".*.comp") to find its saved competitions at boot.
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 or is a string variable that has never had a value; 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,"dead[.].*"is every name starting with "dead.", and a plain.matches any character. A shell-style"*"is not a valid expression. - If the pattern is not a valid expression, the program stops with a type error in
vme.log(unlikeunitdir(), which just fails). - The directory is
strings/under the zone's DIL file directory: the sixth column of the zone's line invme/etc/zonelist, 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
loadstr().
Example
dilbegin wanted_list(pc : unitptr);
var
files : stringlist;
parts : stringlist;
i : integer;
n : integer;
code
{
files := strdir("dead[.].*");
n := length(files);
if (n == 0)
{
sendtext("Nobody is wanted.<br/>", pc);
return;
}
i := 0;
while (i < n)
{
parts := split(files.[i], ".");
sendtext("Wanted dead: " + parts.[1] + "<br/>", pc);
i := i + 1;
}
return;
}
dilend
Lists the players for whom a file "dead.name" was saved with savestr().