twapi has the get_volume_info command [L1 ] for this.
WinXP and following build in fsutil, with which it is possible to retrieve such results as fsutil volume diskfree c:, parse those results, ...
For Unix, of course, ...
See also du and How can I calculate how much disk space is being used in a directory.