This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
K-dence's profile picture

Add a function fs.getSpaceLimit()

Started by K-dence, 26 March 2013 - 04:22 PM
K-dence #1
Posted 26 March 2013 - 05:22 PM
Hi!

Please add a function to get the total space limit in a computer or floppy disk. I think this is good because we can change the disk space in config of CC.

Like this we can make a complete memory utility for our OS or other.

PS: fs.getFreeSpace() is not referenced in wiki.

EDIT : a moderator can lock this topic.
I created a function :

fs.getSpaceLimit = function(_path, _space, _final)
        local final = true
        if(_final ~= nil) then
                final = _final
        end 
        local space = 0
        if(_space ~= nil) then
                space = _space
        end
        local sDir = ""
        if _path ~= nil then sDir = _path end
        local tContent = fs.list( sDir )
        for i, j in pairs( tContent ) do
                local sPath = fs.combine( sDir, j )
        
                        if fs.isDir( sPath ) then
                                if(sPath ~= "rom") then
                                        space = space + 512
                                        space = fs.getSpaceLimit(sPath, space, false)
                                end
                        else
                                space = space + fs.getSize(sPath)
                        end     
        
        end
        if(final == true) then
                return space + fs.getFreeSpace("")
        else
                return space
        end
end
Cruor #2
Posted 26 March 2013 - 11:08 PM
Locked as requested.