C++ has a lot of great libraries to operate on files, folders, and disks. We can create or delete directories by using System Commands that we explained before in this post or we can use C++ standard library methods. In C++ Builder, we can use both of them and we can also use Disk And Directory Support Routines to create or remove directories or to get information about disks, directories, and files. These methods are easy to remember, very friendly, and smart.
In this post, you’ll learn how to get disk size and disk free size information in C++ Builder, as well as how to calculate a disk’s free percentage. By learning how to use disk size and disk free size in C++ Software. It will help you to easily build C++ applications.
How do I get the free space size for a disk in C++ Builder?
Use the DiskFree method (System::SysUtils::DiskFree) which is a SysUtils Method listed in Disk And Directory Support Routines. It returns the number of free bytes on a specified drive. The DiskFree method returns the number of free bytes on the specified drive, where 0 = Current, 1 = A, 2 = B, and so on. DiskFree returns -1 if the drive number is invalid. Note that the DiskFree method is only available on Windows.
Here is the DiskFree Method in C++ Builder:
Here is a simple example of DiskFree() Method in C++ Builder,
How do I get the total size of a disk in C++ Builder?
Use the DiskSize mMethod (System::SysUtils::DiskSize) is a SysUtils Method listed in Disk And Directory Support Routines. It returns the total size, in bytes, of a specified drive. DiskSize returns the size in bytes of the specified drive, where 0 = Current, 1 = A, 2 = B, and so on. DiskSize returns -1 if the drive number is invalid. Note that DiskSize is only available on Windows.
Here is a simple example to DiskSize() Method in C++ Builder,
Is there a full example of using the DiskSize and DiskFree methods in C++?
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.