Task

Beginning from the current directory, or optionally from a directory specified as a command-line argument, determine how many files there are of various sizes in a directory hierarchy.



My suggestion is to sort by logarithmn of file size, since a few bytes here or there, or even a factor of two or three, may not be that significant.

Don't forget that empty files may exist, to serve as a marker.



Is your file system predominantly devoted to a large number of smaller files, or a smaller number of huge files?




without js -- file i/o
sequence sizes = {1},
         res = {0}
atom t1 = time()+1
 
function store_res(string filepath, sequence dir_entry)
    if not find('d', dir_entry[D_ATTRIBUTES]) then
        atom size = dir_entry[D_SIZE]
        integer sdx = 1
        while size>sizes[sdx] do
            if sdx=length(sizes) then
                sizes &= sizes[$]*iff(mod(length(sizes),3)?10:10.24)
                res &= 0
            end if
            sdx += 1
        end while
        res[sdx] += 1
        if time()>t1 then
            printf(1,"%,d files found\r",sum(res))
            t1 = time()+1
        end if
    end if
    return 0 -- keep going
end function
integer exit_code = walk_dir(".", store_res, true)
 
printf(1,"%,d files found\n",sum(res))
integer w = max(res)
--include builtins/pfile.e
for i=1 to length(res) do
    integer ri = res[i]
    string s = file_size_k(sizes[i], 5),
           p = repeat('*',floor(60*ri/w))
    printf(1,"files < %s: %s%,d\n",{s,p,ri})
end for
