C++Introduction to C++Language FeatureLearn C++

How to Get Disk Information in C++ on Windows?

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.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Learn C++

What Is The Priority Queue (std::priority_queue) In Modern C++?

C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?