Got Another. This One is relatively new so there is room so there is plenty of room for refinement. The Script Recursively Monitors File-size of a Sub folder on Windows Operating System. Can be used to Monitor User Directories, Application Folders etc. Although its been tested on folders over half a Terabyte it does take some time to complete when dealing with Folders of that size. ** Untested on Windows Vista/Server 2008 **.
Arguments : Windows Folder Path to Be monitored < 'C:\intellipool' >
Thanks,
/jAzz
-- Comments and Suggestions Welcome
CODE
--[[
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
--]]
------------------------------------------------------------------------------------------------
Name = "SubFolderSize"
Author = " Jazz Alyxzander Turner-Baggs "
VersionMaj = 2
VersionMin = 1
Date = "December 16th, 2008"
Description = "Recursively Enumates Diskspace used by a Sub directory"
----------------------------------------------------------------------------------------------------------
function OnConfigure()
Config = LuaScriptConfigurator()
Config:SetAuthor(Author)
Config:SetDescription(Description)
Config:SetMinBuildVersion(0)
Config:SetScriptVersion(VersionMaj, VersionMin )
Config:AddArgument("Path","Stanard Path of files and subfolders to be iterated Ex<c:\intellipool>",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:SetEntryPoint("main")
return Config
end
----------------------------------------------
-- Global Vars
---------------------------------------------
-- Main Recursive Function
--[[
1) Get Subfolders
2) Recurse on all subfolders,
3) Sum size of files
4) return.
--]]
function FileRecurse(path, k) -- Path = subdirectory , k = folderCount
local FILE = TLuaFile()
local folderList = FILE:GetDirectoryList(path)
local fileList = FILE:GetFileList(path, '*.*')
local fileSize = 0 -- Init Local Size to zero
local folder = ""
-- Recurse Folders
if folderList ~= "" then
while folderList ~= "" do
folderList, folder = stringIterator(folderList, "\n") -- Pop Head from String-Queue
tmpsize, k = FileRecurse(folder,k)
fileSize = fileSize + tmpsize -- Add Sub folder Size To Running Folder Sum
end
end
-- Sum Files
while fileList ~= "" do
fileList, file = stringIterator(fileList, "\n")
if file ~= "" then
fileSize = fileSize + FILE:GetFileSize(file) -- Add File Size to running Folder Size
end
end
return fileSize, k+1
end
-- Pops First Token from string , by given deliminator.
function stringIterator(s1, delim)
if s1 == nil then
return "",""
end
local iCurr = string.find(s1 , "\n")
if iCurr == nil then
return "",""
end
local filePath = string.sub(s1,0,iCurr-1)
s1 = string.sub(s1,iCurr+1)
return s1,filePath
end
----------------------------------------------
function main()
Total = -1 -- Total Size init -1
iConversionFactor = 2 ^ 20 -- Btyes to Output Conversion
iSECONDS_CONVERSION = 1000 -- Seconds to Output Conversion
path = GetArgument(0)
Timer = TLuaTimer()
Timer:Start()
FileSize, FolderCount = FileRecurse(path,0)
FileSize = FileSize / iConversionFactor
time = Timer:Stop() / iSECONDS_CONVERSION
StoreStatisticalData(1,FileSize,0,'MB')
StoreStatisticalData(2,time,0,'Seconds')
SetExitStatus("Last Test(" .. FolderCount .. "): " .. FileSize .. " MB's - " .. time .. " seconds",true)
end
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
--]]
------------------------------------------------------------------------------------------------
Name = "SubFolderSize"
Author = " Jazz Alyxzander Turner-Baggs "
VersionMaj = 2
VersionMin = 1
Date = "December 16th, 2008"
Description = "Recursively Enumates Diskspace used by a Sub directory"
----------------------------------------------------------------------------------------------------------
function OnConfigure()
Config = LuaScriptConfigurator()
Config:SetAuthor(Author)
Config:SetDescription(Description)
Config:SetMinBuildVersion(0)
Config:SetScriptVersion(VersionMaj, VersionMin )
Config:AddArgument("Path","Stanard Path of files and subfolders to be iterated Ex<c:\intellipool>",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:SetEntryPoint("main")
return Config
end
----------------------------------------------
-- Global Vars
---------------------------------------------
-- Main Recursive Function
--[[
1) Get Subfolders
2) Recurse on all subfolders,
3) Sum size of files
4) return.
--]]
function FileRecurse(path, k) -- Path = subdirectory , k = folderCount
local FILE = TLuaFile()
local folderList = FILE:GetDirectoryList(path)
local fileList = FILE:GetFileList(path, '*.*')
local fileSize = 0 -- Init Local Size to zero
local folder = ""
-- Recurse Folders
if folderList ~= "" then
while folderList ~= "" do
folderList, folder = stringIterator(folderList, "\n") -- Pop Head from String-Queue
tmpsize, k = FileRecurse(folder,k)
fileSize = fileSize + tmpsize -- Add Sub folder Size To Running Folder Sum
end
end
-- Sum Files
while fileList ~= "" do
fileList, file = stringIterator(fileList, "\n")
if file ~= "" then
fileSize = fileSize + FILE:GetFileSize(file) -- Add File Size to running Folder Size
end
end
return fileSize, k+1
end
-- Pops First Token from string , by given deliminator.
function stringIterator(s1, delim)
if s1 == nil then
return "",""
end
local iCurr = string.find(s1 , "\n")
if iCurr == nil then
return "",""
end
local filePath = string.sub(s1,0,iCurr-1)
s1 = string.sub(s1,iCurr+1)
return s1,filePath
end
----------------------------------------------
function main()
Total = -1 -- Total Size init -1
iConversionFactor = 2 ^ 20 -- Btyes to Output Conversion
iSECONDS_CONVERSION = 1000 -- Seconds to Output Conversion
path = GetArgument(0)
Timer = TLuaTimer()
Timer:Start()
FileSize, FolderCount = FileRecurse(path,0)
FileSize = FileSize / iConversionFactor
time = Timer:Stop() / iSECONDS_CONVERSION
StoreStatisticalData(1,FileSize,0,'MB')
StoreStatisticalData(2,time,0,'Seconds')
SetExitStatus("Last Test(" .. FolderCount .. "): " .. FileSize .. " MB's - " .. time .. " seconds",true)
end