Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2009
    Posts
    75

    Grin Calculate Folder Size

    Hello everyone. I want to create a function that calculate size of specified folder. It is possible? If yes help me please.

    Thx )

  2. #2
    Join Date
    Jan 2001
    Location
    Anderson Island, WA, USA
    Posts
    2,863
    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...

    Code:
    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
    Last edited by jassing; 07-01-2009 at 02:39 PM.


    (Click here to contact me)
    Providing Independent Professional Consulting Services for
    IndigoRose products, World Wide.
    Located in -8:00 (-7:00 DST) GMT Timezone (Western United States)

  3. #3
    Join Date
    Jul 2009
    Posts
    75

    thx

    Perfectly work! Thank you for help dude!

  4. #4
    Join Date
    Dec 2009
    Posts
    3
    thanks great coding

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts