File size distribution: Difference between revisions

m
→‎{{header|REXX}}: added the REXX computer programming language.
(Added Kotlin)
m (→‎{{header|REXX}}: added the REXX computer programming language.)
Line 400:
log10-or-so(size): 6.0 -> 6 files
Total: 10210127 bytes in 733 files</pre>
 
=={{header|REXX}}==
This REXX version works for Microsoft Windows using the &nbsp; '''dir''' &nbsp; subcommand; &nbsp; extra code was added for
<br>older versions of Windows that used suffixes to express big numbers &nbsp; (the size of a file).
<lang rexx>/*REXX program displays a histogram of filesize distribution of a directory structure. */
numeric digits 20 /*ensure enough decimal digits for #. */
parse arg ds . /*obtain optional argument from the CL.*/
parse source . . path . /* " the path of this REXX program.*/
fID=substr(path, 1 + lastpos('\', path) ) /* " the filename and the filetype.*/
parse var fID fn '.' /* " just the pure filename of pgm.*/
sw=linesize() - 1; if sw<80 then sw=79 /* " terminal width (linesize) - 1.*/
dirOut= fn".OUT" /*construct filename for output of DIR.*/
'DIR' ds '/s /a-d >' dirout /*execute the (DOS) DIR command for DS.*/
call linein 0, 1 /*open output file, point to 1st record*/
maxL=0 /*maximum length of number of records. */
@.=00 /*stemmed array to hold record counts. */
g=0 /*number of good records found (so far)*/
do while lines(dirOut) \== 0
$=linein(dirOUT); if left($, 1)==' ' then iterate /*process data. */
parse upper var $ dat tim sz . /*uppercase suffix*/
if pos('/', dat) ==0 | pos(":", tim)==0 then iterate /*validate dat&tim*/
if pos(',', sz) \==0 then sz=space( translate(sz, , ","), 0) /*SZ has commas? */
if \datatype(sz,'W') then do; #=left(sz, length(sz) - 1) /*SZ has a suffix?*/
if \datatype(#,'N') then iterate /*Meat ¬ numeric? */
sfx= right(sz, 1) /*get the suffix. */
sz=# * 1024 **pos(sfx,'KMGT')/1 /*compute true val*/
end
if sz==0 then L=0 /*handle special case for an empty file*/
else L=length(sz) /*obtain the length of filesize number.*/
g=g + 1 /*bump the counter of # of good records*/
maxL=max(L, maxL) /*obtain the maximum length of filesize*/
@.L=@.L + 1 /*bump counter of category of rec size.*/
end /*j*/
 
if g==0 then do; say 'file not found: ' ds; exit 13; end
say ' record size range count '
hdr= '══════════════════ ═══════ '; say hdr; lenHdr= length(hdr)
mC=0 /*mC: the maximum count for any range.*/
do t=1 to 2 /*T==1 is used to find the max count.*/
do k=0 to maxL; mC=max(mC, @.k); if t==1 then iterate
select
when k==0 then y= ' zero '
when k==1 then y= ' 1 ──► 9 '
when k==2 then y= ' 10 ──► 99 '
when k==3 then y= ' 100 ──► 999 '
when k==4 then y= ' 1000 ──► 9999 '
otherwise y= '10^'left(k-1,2) "──► 10^"left(k,2) '-1'
end /*select*/
say y || right(@.k, 8) copies('─', max(1, (@.k / mC * sw % 1) - lenHdr) )
end /*k*/
end /*y*/
/*stick a fork in it, we're all done. */
'ERASE' dirOut /*perform clean─up (erase a work file).*/</lang>
{{out|output|text=&nbsp; when using the default input: &nbsp; (which in this case was the &nbsp; '''C:''' &nbsp; drive.)}}
<pre>
record size range count
══════════════════ ═══════
zero 1591 ─
1 ──► 9 207 ─
10 ──► 99 2023 ─
100 ──► 999 5473 ─
1000 ──► 9999 25207 ────────────────────────────────────────────────────────────────────
10^4 ──► 10^5 -1 14615 ────────────────────────────
10^5 ──► 10^6 -1 5234 ─
10^6 ──► 10^7 -1 1017 ─
10^7 ──► 10^8 -1 151 ─
10^8 ──► 10^9 -1 3 ─
10^9 ──► 10^10 -1 1 ─
</pre>
 
=={{header|Sidef}}==