Page 1 of 1

Lazarus – MacOS – Determine available disk space

Lazarus – MacOS – Determine available disk space

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.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.

RSS Feed

Home Forums Software Development Delphi, Lazarus, Free Pascal Lazarus – MacOS – Determine available disk space

This topic contains 0 replies, has 1 voice, and was last updated by  hans 4 months, 2 weeks ago.

Viewing 1 post (of 1 total)
  • Author
  • 12110


    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
      diskID := AddDisk('/Volumes/LIBREELEC/overlays');
      ShowMessage('Available disk space = '+ IntToStr( DiskFree(diskID) ) + ' bytes');

    And that’s all there is to it …

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.