File size distribution: Difference between revisions

Content added Content deleted
(Add Julia language)
Line 144: Line 144:
</pre>
</pre>
Note that it is possible to track files up to 10^24 (Yottabyte) in size with this implementation, but if you have a file that large, you shouldn't be needing such programs. :)
Note that it is possible to track files up to 10^24 (Yottabyte) in size with this implementation, but if you have a file that large, you shouldn't be needing such programs. :)

=={{header|Julia}}==
{{works with|Julia|0.6}}

<lang julia>using Humanize

function sizelist(path::AbstractString)
rst = Vector{Int}(0)
for (root, dirs, files) in walkdir(path)
files = joinpath.(root, files)
tmp = collect(filesize(f) for f in files if !islink(f))
append!(rst, tmp)
end
return rst
end

byclass(y, classes) = Dict{eltype(classes),Int}(c => count(c[1] .≤ y .< c[2]) for c in classes)

function main(path::AbstractString)
s = sizelist(path)
cls = append!([(0, 1)], collect((10 ^ (i-1), 10 ^ i) for i in 1:9))
f = byclass(s, cls)

println("filesizes: ")
for c in cls
@printf(" - between %8s and %8s bytes: %3i\n", datasize(c[1]), datasize(c[2]), f[c])
end
println("\n-> total: $(datasize(sum(s))) bytes and $(length(s)) files")
end

main(".")</lang>

{{out}}
<pre>filesizes:
- between 0.0 B and 1.0 B bytes: 0
- between 1.0 B and 10.0 B bytes: 1
- between 10.0 B and 100.0 B bytes: 44
- between 100.0 B and 1.0 kB bytes: 1068
- between 1.0 kB and 10.0 kB bytes: 250
- between 10.0 kB and 100.0 kB bytes: 7
- between 100.0 kB and 1.0 MB bytes: 4
- between 1.0 MB and 10.0 MB bytes: 2
- between 10.0 MB and 100.0 MB bytes: 0
- between 100.0 MB and 1.0 GB bytes: 0

-> total: 7.3 MB bytes and 1376 files</pre>


=={{header|Perl 6}}==
=={{header|Perl 6}}==