lsdir

Table of Contents

Prototype: lsdir(path, regex, include_base)

Return type: slist

Description: Returns a list of files in the directory path matching the regular expression regex.

If include_base is true, full paths are returned, otherwise only names relative to the directory are returned.

Arguments:

  • path: string, in the range: .+
  • regex: regular expression, in the range: .*
  • include_base: one of
    • true
    • false
    • yes
    • no
    • on
    • off

Example:

body common control
{
      bundlesequence => { "example" };
}

bundle agent example
{
  vars:
      "listfiles" slist => lsdir("/etc", "(p.sswd|gr[ou]+p)", "true");
      "sorted_listfiles" slist => sort(listfiles, "lex");

  reports:
      "files in list: $(sorted_listfiles)";
}

Output:

R: files in list: /etc/group
R: files in list: /etc/passwd

Tips:

  • Filter out the current (.) and parent (..)directories with a negative look ahead. lsdir( "/tmp", "^(?!(\.|\.\.)).*", false ).

Notes:

History: Was introduced in 3.3.0, Nova 2.2.0 (2011)