Welcome to the Creatures Wiki! Log in and join the community.

FILE GLOB

From Creatures Wiki
Jump to navigation Jump to search

FILE GLOB is a CAOS command which lists files.

Usage[edit]

Syntax: FILE GLOB dir (int) spec (string)

This searches the directory specified by dir for all files matching the pattern spec. The results are sent to the input stream: the first line an integer n containing the number of files found, the next n lines containing a filename each. The filenames are global.

dir should be 0 for the current world journal directory, 1 for the main one. The following special codes are recognised in spec at least in lc2e: ? matches any single character, * matches any number of characters. [...] matches any of the characters in the brackets. Ranges (e.g. A-Z, A-z) are allowed, as are some character classes (e.g. [:alnum:]), probably those allowed by PCRE.

Warning!
CEE allows spec to reach above the journal directory, and some third-party agents use this to check for the presence of genetic files, by letting spec="../Genetics/xxxxxx". However, this is a possible security hole and the behaviour is deprecated; openc2e will probably not allow searching above the game directory.

Since this command opens the input stream, you should use FILE ICLO when you are done with it.

Examples[edit]

This is valid, and lists the contents of the current journal directory:

FILE GLOB 0 "*"
SETV va00 INNI
SETS va99 INNL * discard rest of line
LOOP
  ADDV va01 1
  OUTS INNL
  OUTS "\n"
UNTL va01 eq va00
FILE ICLO

Result:
    /home/alex/.dockingstation/My Worlds/hh/Journal/build
    /home/alex/.dockingstation/My Worlds/hh/Journal/wtype

This is inadvisable, and checks if bondi DNA is available:

FILE GLOB 1 "../Genetics/*bondi*"
DOIF INNI ne 0
  * inject
ENDI
FILE ICLO

See also[edit]