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

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

How can I get disk size information in C++ Builder? How can I get disk free size information in C++ Builder? How can I calculate free percentage of a disk? Let’s answer these questions.

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.

Let’s see how we can get disk size and disk free size in C++ Builder

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 DiskFree method is only available on Windows.

Here is the DiskFree Method in C++ Builder:

Here is a simple example to 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.

close

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

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++ComponentsDatabaseIntroduction to C++Language FeatureLearn C++

Get To Know The Powerful C++ Data Bindings In Windows Apps

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

How to Create a New Windows FMX Static Library In C++

C++C++11C++14C++17Introduction to C++Learn C++

How To Use C++ front() And back() Methods Of Vectors

C++Generic ProgrammingIntroduction to C++Language FeatureLearn C++

5 Things You Need To Know About Optimization In C++ Builder

pt_BRPortuguese