Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- local baseDir = args[1]
- local countReadOnly = args[2] == "-y"
- local function getDirSize(dir, depth)
- local sizes = {}
- local totalSize = 0
- for i, file in pairs(fs.list(dir)) do
- if fs.exists(dir .. "/" .. file) and (countReadOnly and (fs.isReadOnly(fs.combine(dir, file)))) or
- (countReadOnly == false and fs.isReadOnly(fs.combine(dir, file)) == false) then
- if not fs.isDir(dir .. "/" .. file) then
- totalSize = totalSize + fs.getSize(dir .. "/" .. file)
- table.insert(sizes, { name = dir .. "/" .. file, size = fs.getSize(dir .. "/" .. file) })
- else
- local dirSize, dirSizes = getDirSize(dir .. "/" .. file, depth + 1)
- totalSize = totalSize + dirSize
- for i, file in pairs(dirSizes) do
- if file then
- sizes[#sizes + 1] = file
- end
- end
- end
- end
- end
- return totalSize, sizes
- end
- local max = fs.getCapacity(baseDir)
- local total, sizes = getDirSize(baseDir, 0)
- term.clear()
- term.setCursorPos(1, 1)
- for i, file in pairs(sizes) do
- print(file.name .. ": " .. (file.size / 1000) .. " kb")
- end
- print("\ntotal size: " .. (total / 1000) .. " kb")
- print(string.format("%.2f%% space taken up", tostring((total / max) * 100)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement