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

How To Check If A Directory On Windows Is Empty In C++?

C++ has a lot of great libraries to operate on every case, on every item. 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 get answers to these questions:

  • How can I check if a Directory on Windows is Empty or Not?
  • How can I use IsEmpty() Method on Directories?

Learning how to use IsEmpty() Method in C++ Builder will help you to easily build C++ applications with the use of C++ Software.

How do I check a directory to see if it is empty using C++ Builder?

The IsEmpty Method (System::IOUtils::TDirectory::IsEmpty) is a SysUtils Method listed in Disk And Directory Support Routines that checks whether a given directory is empty.

Here is the Syntax for the IsEmpty Method in C++ Builder:

We can call IsEmpty to check whether a given directory is empty. An empty directory is considered to have no files or other directories in it. IsEmpty returns true if the directory is empty; false otherwise. The following table lists the parameters expected by this method.

NameMeaning
PathPath of the directory being checked.

Note: If the Path parameter is an empty string, IsEmpty returns false.

Here is a simple example to IsEmpty() Method in C++ Builder,

Is there a full example of how to use the IsEmpty method in C++ Builder?

Here is Full C++ Builder VCL example that creates a empty folder and checks if this directory is empty,

This method can be used before using the Remove Directory Methods like RmDir() or other methods, thus you can warn user that folder is not empty.

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.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

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++?