CODE
----------------------------------------------------------------------------------------------------------
-- Name: FileCheck.lua
-- Author: Intellipool AB
-- Version: 1.1
-- Date: 2006-03-18
-- Description: Checks if files with a certain extension in a directory is up to date. Time is calculated based
-- on the supplied time threshold in minutes.
-- Arguments:
-- Directory path
-- File extension
-- Max age, in minutes
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
-- Creates a table of lines ending with crlf
function MakeTable(s)
    local sInData = s;
    iLastPos = 0;
    
    t = {};
    max = string.len(sInData);
    for count = 0, max do
        cCharacter = string.byte(sInData,count);
        if cCharacter == 10 then
            local sTemp = string.sub(sInData,iLastPos,count-1);
            table.insert(t,sTemp);
            iLastPos = count+1;
        end
    end
    return t;
end


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

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

file = TLuaFile:new()
sFileList = file:GetFileList(sFilePath ,sFileExt)
tFileTable = MakeTable(sFileList);

----------------------------------------------------------------------------------------------------------
-- Loop trough all files
nTableMax = table.getn(tFileTable);
if nTableMax == 0 then
    -- Change false to true if you want test to finish in OK state if no files are in the directory.
    SetExitStatus("No files in directory",false);
    return;
end

sErrorString = "";

for count=1, nTableMax do
    sTemp = tFileTable[count];
    Time = TLuaDateTime:new()
    Time = file:GetFileModifiedTime(sTemp);
    CurrentTime = TLuaDateTime:new()
    DiffTime = TLuaDateTime:new()
    DiffTime:CreateSpan(0,iMaxAge,0);
    CurrentTime:Sub(DiffTime)
    
    if CurrentTime:Less(Time) == false then
        sErrorString = sErrorString .. "File " .. sTemp .. "older then " .. iMaxAge .." minutes\n";
    end
end
if sErrorString ~= "" then
    sTemp = "One or more files is too old\n\n" .. sErrorString;
    SetExitStatus(sTemp,false);
else
    SetExitStatus("Files are fresh",true);
end