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