Manual:DIL Manual/strdir()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:15, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 (unlike unitdir(), which just fails).
  • The directory is strings/ under the zone's DIL file directory: the sixth column of the zone's line in vme/etc/zonelist, or else dil_file_dir in server.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().

See also