LUALoriotPro WEB site

LoriotPro scripting documentation
Extensions for LUA language

Table of contents Search function

Print the current page Mail this  link UTUBE Channel version française

lp.FindFile

LoriotPro has extended the LUA sripting language by providing its own LUA libraries. The new functions provided are dedicated to the creation of monitoring and SNMP automation application.

Syntax

number = lp.FindFile('path','ext','array');

number = lp.FindFile('path','ext','array',index);

Description

Search for one or multiple files by name in a directory. The result are return in an array

Parameters

‘path’                   The path to the directory

‘ext’                     The file name and extension

‘array’ A table for the answer.

index                  Equal to 1 if the table should start with 1 and support the ipairs(array) LUA function.

Return Values

number           The number of files found.

Warning  ! The standard function of LoriotPro returns indexed table using the 0 value as first index value. LUA table use the value 1 instead. This state can generate error when using table.

array[0] ..[number-1]                   The file name found in an array (array[1] … array[number] if index)

Return nil if an error occurs

Example

The following example search all the file with "dll" as extension in the bin directory and display the result.

j=lp.FindFile(lp.GetPath(),"*.dll","a");
if j then
lp.Print('Find ',j,' Files\n');
       for i=0,(j-1) do
             lp.Print(a[i],"\n");
       end
lp.Print(" table.getn \n");
       for i=0,table.getn(a) do
             lp.Print(a[i],"\n");
       end
end

lp.Print(" ipairs \n");
j=lp.FindFile(lp.GetPath(),"*.dll","a",1);
if j then
for key,value in ipairs(a) do lp.Print("[",key,"] [",value,"]\n")
end

end

Warning  ! If you want to use the \ character in the path ypu should use the \\ instead. The \ character is use for escape sequence only in LUA.

find file in LUA with LoriotPro


www.loriotpro.com