File size distribution: Difference between revisions

Add Factor
(Add Factor)
Line 291:
Number of files: 7,874
Total file size: 11,963,566,673 bytes
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2020-03-02}}
<lang factor>USING: accessors assocs formatting io io.directories.search
io.files.types io.pathnames kernel math math.functions
math.statistics namespaces sequences ;
 
: classify ( m -- n ) [ 0 ] [ log10 >integer 1 + ] if-zero ;
 
: file-size-histogram ( path -- assoc )
recursive-directory-entries
[ type>> +directory+ = ] reject
[ size>> classify ] map histogram ;
 
current-directory get file-size-histogram dup
[ "Count of files < 10^%d bytes: %4d\n" printf ] assoc-each
nl values sum "Total files: %d\n" printf</lang>
{{out}}
<pre>
Count of files < 10^0 bytes: 20
Count of files < 10^1 bytes: 742
Count of files < 10^2 bytes: 3881
Count of files < 10^3 bytes: 2388
Count of files < 10^4 bytes: 3061
Count of files < 10^5 bytes: 486
Count of files < 10^6 bytes: 78
Count of files < 10^7 bytes: 27
Count of files < 10^8 bytes: 3
Count of files < 10^9 bytes: 1
 
Total files: 10687
</pre>
 
1,808

edits