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

How To Delete A File On Windows In C++ Builder

How can I delete a file in C++ Builder? How can I use DeleteFile method in C++ Builder? Let’s answer these questions.

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.

How can I delete a file by using the DeleteFile method in C++?

DeleteFile Method (System::SysUtils::DeleteFile Method) is a SysUtils Method listed in Disk And Directory Support Routines that deletes a file from disk. DeleteFile deletes the file named by FileName from the disk. If the file cannot be deleted or does not exist, the function returns False.

Note that DeleteFile can delete a symbolic link from a file or a directory and is the preferred method for deleting symlinks.

Here is the Syntax for the DeleteFile() 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 DeleteFile() Method in C++ Builder,

is there a full Example of using the DeleteFile method in C++ Builder?

Here is Full C++ Builder VCL example that deletes a file,

Please be careful when you use this method, always ask to user with full name of file if he is sure to delete it.

Where can I find more information on file handling routines in C++?

Use this dynamic link to search for more path manipulation methods: https://learncplusplus.org/?s=file

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

en_USEnglish