'Display remaining and needed disk space in a WPF App in C#

I have a WPF application that allows a bunch of checkboxes to be selected which govern which applications you are going to install. I am trying to make it so that the user can see how much space is empty when they select a folder and how much will be required. Kind of like the Visual Studio Installer where, as you select more components, the disk space is updated.

I would like to have that information displayed on a label. I have a FolderBrowserDialog which allows you to select the path. Say for instance- a label for empty space (lblEmptySpace) and one for required space which is updated as more applications are selected (lblRequiredSpace).



Solution 1:[1]

You can check official Microsoft documentation here

Example:

private static long GetTotalFreeSpace(string driveName)
{
    foreach (DriveInfo drive in DriveInfo.GetDrives())
    {
        if (drive.IsReady && drive.Name == driveName)
        {
            return drive.TotalFreeSpace;
        }
    }
    return -1;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1