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- Path to base directory - in the range:.+regex: regular expression - Regular expression to match files or blank - in the range:.*include_base: - Include the base path in the list - one oftruefalseyesnoonoff
Example:
code
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:
code
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 ).
History: Was introduced in 3.3.0, Nova 2.2.0 (2011)