Help - Search - Members - Calendar
Full Version: count number of file/directory recusively ?
Intellipool Network Monitor - Forum > Intellipool Network Monitor > Lua scripts
cdiscount
Hello,
I'am trying to make a lua script in order to count the number of files/directory in a tree directory ( recursively)
I have checked it on a regular lua environnement installation.
When I use INM to launch the script an error message on "lfs library" occure. I don't know where I need to install the lfs library on inm?

Thx
Bertrand

----------------------------------------------------------------------------------------------------------
-- Name: FilecounterRecursively.lua
-- Authors:
-- Version: 1.0
-- Date: 2008-09-08
-- Description: Counts number of files in a directory tree
-- Arguments:
-- Directory path
-- Max number of files
-- Separate args with spaces
-- Unix filesystem "/" not "\"
----------------------------------------------------------------------------------------------------------

-- User must supply path and max number of files in directory tree
iArgumentCount = GetArgumentCount()
if iArgumentCount < 2 then
SetExitStatus("Too few arguments",false)
return
end

-- Get path and max number of files
local sFilePath = GetArgument(0)
local iMaxNumberOfFiles = tonumber(GetArgument(1))


require"lfs"


-- Fontion comptage de fichiers et de repertoires
local iNbFichier = 0
local iDirectoryCount = 0

function repertoirecheck (repertoireAChecker)
for file in lfs.dir(repertoireAChecker) do
if file ~= "." and file ~= ".." then
io.write (repertoireAChecker.."/"..file,"\n")
local f = repertoireAChecker.."/"..file
local attr = lfs.attributes (f)
assert (type(attr) == "table")
if attr.mode == "directory" then
iDirectoryCount = iDirectoryCount + 1
repertoirecheck(repertoireAChecker.."/"..file)
else
iNbFichier = iNbFichier + 1
end

end
end
end

repertoirecheck(sFilePath)

--io.write("nombre de fichier : ",iNbFichier,"\n")


-- Write stats
StoreStatisticalData(0,iNbFichier);

-- Do "test"
print(iNbFichier);
if iNbFichier <= iMaxNumberOfFiles then
SetExitStatus("Test OK, Files: ".. tostring(iNbFichier).." of "..tostring(iMaxNumberOfFiles),true);
else
SetExitStatus("Too Many Files: ".. tostring(iNbFichier).." of "..tostring(iMaxNumberOfFiles),false);
end
RA
QUOTE
I don't know where I need to install the lfs library on inm?


The LFS library is a 3rd party library that have not been compiled into INM. All libraries needs to be compiled into INM and cannot be loaded in runtime.

The problem with the LFS library is that its developed for Lua 5.1 , while INM uses Lua 5.0.

Lua 5.1 contains some standard library changes that would break many current scripts. So we have no time table when or if we will upgrade to Lua 5.1
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.