IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Example: Count files in directory
RA
post Mar 3 2006, 04:08 PM
Post #1


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



Download a free trial of Intellipool Network Monitor today!
More information about Intellipool Network Monitor !



CODE
----------------------------------------------------------------------------------------------------------
-- Name: Filecounter.lua
-- Author: Intellipool AB
-- Version: 1.0
-- Date: 2006-03-03
-- Description: Counts number of files in a directory
-- Arguments:
-- Directory path
-- Max number of files
----------------------------------------------------------------------------------------------------------

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

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

file = TLuaFile:new()
sFileList = file:GetFileList(sFilePath ,"*.*")

-- "count" files,string returned will contain all files in the directory, separated by CR
iLen = string.len(sFileList);
iFileCount =0
for count = 0, iLen do
    cCurrentChar = string.byte(sFileList,count);
    if cCurrentChar == 10 then
 iFileCount = iFileCount +1;
    end
end
file:Close();

-- Do "test"
print(iFileCount);
if iFileCount < iMaxNumberOfFiles then
    SetExitStatus("Test ok",true);
else
    SetExitStatus("More files in directory then allowed",false);
end
Go to the top of the page
 
+Quote Post
Guest_Guest_Eric_*_*
post Mar 6 2006, 05:44 PM
Post #2





Guests






I have modified this script to show realtime file count and create a graph of it:

CODE
----------------------------------------------------------------------------------------------------------
-- Name: Filecounter.lua
-- Authors: Eric Strauss
-- Version: 1.1
-- Date: 2006-03-06
-- Description: Counts number of files in a directory
-- 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
iArgumentCount = GetArgumentCount()
if iArgumentCount < 2 then
   SetExitStatus("To few arguments",false)
   return
end

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

file = TLuaFile:new()
sFileList = file:GetFileList(sFilePath ,"*.*")

-- "count" files,string returned will contain all files in the directory, separated by CR
iLen = string.len(sFileList);
iFileCount =0
for count = 0, iLen do
   cCurrentChar = string.byte(sFileList,count);
   if cCurrentChar == 10 then
      iFileCount = iFileCount +1;
   end
end
file:Close();

-- Write stats
StoreStatisticalData(0,iFileCount,iMaxNumberOfFiles,"Files");

-- Do "test"
print(iFileCount);
if iFileCount < iMaxNumberOfFiles then    
   SetExitStatus("Test OK, Files: ".. tostring(iFileCount).." of "..tostring(iMaxNumberOfFiles),true);  
else
   SetExitStatus("Too Many Files: ".. tostring(iFileCount).." of "..tostring(iMaxNumberOfFiles),false);
end
Go to the top of the page
 
+Quote Post
David Spindler
post Apr 28 2006, 01:49 PM
Post #3


New to the forum


Group: Members
Posts: 4
Joined: 6-March 06
From: Giessen
Member No.: 216



Hi,

we use this lua scripts for 4 monitors. 3 Monitors works correct and without any problem but from one monitor I get this message

"Syntax error in LUA script count files in dir.lua, [string ""]:40: error in function 'StoreStatisticalData'. argument #3 is 'nil'; 'number' expected."

I'm wondering because If there is a syntax error in the script, I should get this message from all monitors or not?

Any ideas to solve the problem?

Kind regards,

David
Go to the top of the page
 
+Quote Post
RA
post May 9 2006, 10:10 PM
Post #4


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



have you specifed the second argument as a number ?

The nil values comes from the variable iMaxNumberOfFiles that is created by GetArgument.

Sorry about the very late reply.


--------------------
Go to the top of the page
 
+Quote Post
David Spindler
post May 16 2006, 03:43 PM
Post #5


New to the forum


Group: Members
Posts: 4
Joined: 6-March 06
From: Giessen
Member No.: 216



No problem! It's not a hugh problem for us.

I have specified this:

C:\Program Files\Achab\Archive Server for MDaemon\engine\queue 200

Is it possible that the spaces are the problem?
Go to the top of the page
 
+Quote Post
RA
post May 16 2006, 03:55 PM
Post #6


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



Try to enclose the path in quotation marks.


--------------------
Go to the top of the page
 
+Quote Post
David Spindler
post Jul 28 2006, 08:18 AM
Post #7


New to the forum


Group: Members
Posts: 4
Joined: 6-March 06
From: Giessen
Member No.: 216



Sorry for my late response...

unfortunally quotation marks doesn't help...

any other ideas?
Go to the top of the page
 
+Quote Post
eric
post Aug 17 2006, 03:36 PM
Post #8


New to the forum


Group: Members
Posts: 7
Joined: 13-February 06
Member No.: 207



Have you tried "/" instead of "\" in your path?
Just an idea...
Go to the top of the page
 
+Quote Post
afaure
post Sep 4 2006, 03:53 PM
Post #9


Frequent user
**

Group: Members
Posts: 65
Joined: 28-April 05
From: France
Member No.: 87



Is it possible to use UNC to specify folder name ?
Go to the top of the page
 
+Quote Post
RA
post Sep 4 2006, 04:39 PM
Post #10


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



No, the path is relative to the object that executes the script.


--------------------
Go to the top of the page
 
+Quote Post
danielh
post Feb 23 2007, 01:37 PM
Post #11


Rookie
*

Group: Members
Posts: 24
Joined: 5-June 06
Member No.: 297



For me, it seems like this script broke when upgrading to the latest version of INM.
Getting the following error message on both my monitors using this script.

Syntax error in LUA script Filecounter.lua, [string ""]:37: error in function 'StoreStatisticalData'.
argument #1 is 'nil'; 'number' expected.
Go to the top of the page
 
+Quote Post
RA
post Feb 27 2007, 04:52 PM
Post #12


INM wizard
**********

Group: Root Admin
Posts: 2,314
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



Seems like a small problem with the export. Will fix in next patch.

Until then substitute the following constant with the corrsponding numbers:

LUA_RECORDSET_1 = 0

LUA_RECORDSET_2 = 1

LUA_RECORDSET_3 = 2

LUA_RECORDSET_4 = 3


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 8th September 2010 - 07:47 AM