This could surely be optimized a bit (e.g. to avoid `stat` ing the files twice
- once to see if they are directories and once to get file size), but it might
get you started:
import os
proc du(rootPath: string): BiggestInt =
result = getFileInfo(rootPath).size
for path in walkDirRec(rootPath):
result += getFileInfo(path).size
echo du(".")
Run
There are also, of course, details like "allocated blocks" vs "allocated
seekable address space" (in Unix land `st_blocks` vs `st_size`). Accommodating
those things usually starts costing you portability as not all filesystems
support "holes" in files (greater address space than allocated blocks). If you
care about that you could also import posix and do you own `stat` calls, etc.