Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!





Share:
Notifications
Clear all

Lazarus - MacOS - Determine available disk space  

  RSS

Hans
 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1363
June 5, 2019 1:07 AM  

For one of my projects (ApplePi-Baker) I needed the ability to see if there is enough disk space available to store a temporary file.
Unfortunately, some of the system API's give very interesting numbers that were of no use to me.
The function "df" does give good info, but I wanted to avoid using command-line tool.

So this is what I was looking for;

Given the path of a file, for example "/Volumes/LIBREELEC/overlays" (USB drive), or "/users/Username" (Mac system disk), I wanted to know how much space was available on the disk this fpath was stored on.

Lazarus Pascal keeps amazing me with its handy little tools, and this is how it's done (MacOS and probably Linux as well).
First we need to "add" the "disk" using "AddDisk" - it appears we can just enter the path where we'd like to store our data later.
This returns a byte to identify the disk, which is then passed to the function "DiskFree".

... 
uses ... SysUtils ...; // default included in a project
...
var
  diskID:byte;
begin
  diskID := AddDisk('/Volumes/LIBREELEC/overlays');
  ShowMessage('Available disk space = '+ IntToStr( DiskFree(diskID) ) + ' bytes');
end;

And that's all there is to it ...


ReplyQuote
Share: