View Full Version : Calculate Folder Size
Benjamin
07-01-2009, 08:21 AM
Hello everyone. I want to create a function that calculate size of specified folder. It is possible? If yes help me please.
Thx )
jassing
07-01-2009, 03:35 PM
Sure it's possible -- you'll want to use File.Find() and scan recursively. Then for each file; get it's size using File.GetSize() and sum them up.
This will give you the folder's files space in use; not the actual space the files take up. (there's a subtle difference)
below is pure air code (ie: untested) but should get you going...
function Folder.GetSize( cFolder )
--[[
Function returns -1 if folder does not exist, otherwise
it returns the sum of all files w/in it.
--]]
local nSize=-1;
if Folder.DoesExist( cFolder ) then
local tFiles = File.Find(cFolder,"*.*",true,false);
nSize = 0;
if tFiles and type(tFiles) == "table" then
local x;
for x=1,Table.Count(tFiles) do
nSize = nSize + File.GetSize( tFiles[x] );
end
end
end
return nSize;
end
Benjamin
07-02-2009, 05:48 AM
Perfectly work! Thank you for help dude! :)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.